Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Displaying information matched with the id?
Old 11-21-2005, 08:36 AM Displaying information matched with the id?
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
Im trying to display a users details, but I don't know how to display the users details with their id.

PHP Code:
mysql_connect("localhost","-","-");
mysql_select_db("-");

$result MYSQL_QUERY("SELECT * FROM users");
$worked mysql_fetch_array($result);

$username $worked[username];

echo 
"<h1>View Information</h1>\n";
echo 
"Username: $username<br \>\n"
That's what I got so far but how $username be the username from id say 6? So far it only displays id 1 information which is mine. Any help?
Ickie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-21-2005, 01:49 PM
TrentonD's Avatar
Ultra Talker

Posts: 253
Location: Calgary, Alberta, Canada
Trades: 0
If you change your query to something like this:

SELECT * FROM users WHERE id='6'

Then it should do what you want. Obviously, "id" is the column name, and you could change the "6" to be a variable, which can be defined in your script.
__________________
Signature Coming Soon! :)
Please login or register to view this content. Registration is FREE
TrentonD is offline
Reply With Quote
View Public Profile Visit TrentonD's homepage!
 
Old 11-21-2005, 08:04 PM
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
I had to do it by username, I didn't want to do that in the first place because I haven't made my register page detect if their is already a user with that name or not.

PHP Code:
if (session_is_registered('username') == true) {
mysql_connect("localhost","-","-");
mysql_select_db("-");

$result mysql_query("SELECT * FROM users WHERE username='$username'");
$row mysql_fetch_row($result);

echo 
"Username: $row[1]<br \>\n";   
echo 
"E-mail: $row[3]<br \>\n";
echo 
"Website: $row[4]<br \>\n";
echo 
"MSN: $row[5]<br \>\n";
echo 
"Yahoo!: $row[6]<br \>\n";
echo 
"ICQ: $row[7]<br \>\n";
echo 
"Location: $row[8]<br \>\n";
echo 
"Occupation: $row[9]<br \><br \>\n"
I set the username session from the login page, and on the login page you don't put your id in so I couldn't add it to the session.
Ickie is offline
Reply With Quote
View Public Profile
 
Old 11-22-2005, 12:13 AM
TrentonD's Avatar
Ultra Talker

Posts: 253
Location: Calgary, Alberta, Canada
Trades: 0
Ok, but it is working now, though?
__________________
Signature Coming Soon! :)
Please login or register to view this content. Registration is FREE
TrentonD is offline
Reply With Quote
View Public Profile Visit TrentonD's homepage!
 
Old 11-22-2005, 05:14 AM
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
You tell me
http://host.inc.md/
Oh, and yes it is working. But still... I would have prefered it be by user's id instead of username.
Ickie is offline
Reply With Quote
View Public Profile
 
Old 11-22-2005, 06:07 PM
TrentonD's Avatar
Ultra Talker

Posts: 253
Location: Calgary, Alberta, Canada
Trades: 0
Ahh k, thats good. Just remember, you can always use it with ID by changing the WHERE to id='$id'
__________________
Signature Coming Soon! :)
Please login or register to view this content. Registration is FREE
TrentonD is offline
Reply With Quote
View Public Profile Visit TrentonD's homepage!
 
Old 11-23-2005, 02:07 AM
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
But how do I define $id? I can't... well I can, but don't know how.
Ickie is offline
Reply With Quote
View Public Profile
 
Old 11-23-2005, 06:13 AM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
get it from the database is the obvious one

in your second example it would be $row[0] depending on the order of columns in your table and assuming id is the first column.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Displaying information matched with the id?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.77450 seconds with 12 queries