Jump to content

assigning query results to variables


tribal

Recommended Posts

hi guys got a quick ??

 

i have a database with 4 columns: username, real_name, age and sex

 

the user logs into the site and does an automatic query of his information

 

i need to display to the user an output report which looks something like this:

 

Welcome <? $username ?> //username variable comes from login session

 

Your real name is <? $real_name ?>

Your age is <? $age ?>

etc..

 

all these variables are from the database query // Select * from users where username = $username

 

how do i assign the query results to the output variables ? thanks

Link to comment
https://forums.phpfreaks.com/topic/970-assigning-query-results-to-variables/
Share on other sites

if youre using

 

$query = \"Select * from users where username = \'$username\'\";

 

go like this:

 

$info = mysql_fetch_array(mysql_query($query)) or die(mysql_error());

$username = $info[\'username\'];

$real_name = $info[\'real_name\'];

$age = $info[\'age\'];

$sex = $info[\'sex\'];

 

the row that you select goes into the $info array, which you can then split up into various variables.

You got it. Your echo statement is a little off, though:

 

[php:1:753995bc06]echo \"Your real name is: $real_name\";[/php:1:753995bc06]

 

When using double quotes, you can include variables in your echos without having to worry about running into any parsing errors (for the most part, anyway).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.