开发者

Personalized Welcome Messages

开发者 https://www.devze.com 2022-12-12 20:20 出处:网络
How do I create a welcome message on my home page with user\'s name in it? Dragging dynamic fields from the recordset onto my page does not work:

How do I create a welcome message on my home page with user's name in it?

Dragging dynamic fields from the recordset onto my page does not work:

<cfoutput>#Recordset1.Username#</cfoutput>.

It keeps using the first username in the table, not the user I am logged in as. Do I have to add some开发者_运维百科thing to my Application.CFC page? I'm using ColdFusion, Dreamweaver and MySQL if it makes any difference.

Thanks for your help.


Note: if you show all the code (how do you log in, how do you query the dataset), it will help us to help you.

Few very general advices for now.

The reason is becasue you select all (or at least more than one) records. When you do the output only once CF shows only first record from dataset. You can check this by looping over the dataset:

<cfloop query="Recordset1">
<cfoutput>#Recordset1.Username#</cfoutput><br />
</cfloop>

It should show all your records.

As Jason pointed you should select only single record of your user. When you perform login act, save user # (typically primary key, id) in Session scope (say, in Session.userid) and use it in queries later like this (I dont know your query, so this is just to show the idea):

<cfquery datasource="datasourceName" name="Recordset1">
    SELECT Username FROM users WHERE id = <cfqueryparam cfsqltype="cf_sql_integer" value="#Session.userid#" />
</cfquery>

Supposing you have unique id's as PK, you'll get only one record in Recordset1, so your initial output will show correct username.


Seems like you need to add a where clause into your query.

0

精彩评论

暂无评论...
验证码 换一张
取 消