tribal Posted September 1, 2003 Share Posted September 1, 2003 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 Quote Link to comment Share on other sites More sharing options...
akitchin Posted September 1, 2003 Share Posted September 1, 2003 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. Quote Link to comment Share on other sites More sharing options...
tribal Posted September 1, 2003 Author Share Posted September 1, 2003 great! ill try that, thank you! Quote Link to comment Share on other sites More sharing options...
tribal Posted September 1, 2003 Author Share Posted September 1, 2003 one more question, so if i want to display real name for example after doing the query, i would do this? $real_name = $info[\'real_name\'] echo \"your real name is:\" $real_name; Quote Link to comment Share on other sites More sharing options...
Dissonance Posted September 1, 2003 Share Posted September 1, 2003 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). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.