master82 Posted September 5, 2006 Share Posted September 5, 2006 What is wrong with this code?[code]<?phpinclude("database.php");$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");if (!$userstable) { echo 'Could not run users query: ' . mysql_error(); exit;}$user = mysql_fetch_row($userstable);//testingecho $user[userid];echo $user[username];?> [/code] When I run it I donr get any errors, just a blank page ??? Quote Link to comment Share on other sites More sharing options...
zawadi Posted September 5, 2006 Share Posted September 5, 2006 try this:[quote]<?phpinclude("database.php");$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");if (!$userstable) { echo 'Could not run users query: ' . mysql_error(); exit;}$user = mysql_fetch_row($userstable);//testingecho $user[0];echo $user[1];?> [/quote]you may need to edit the numbers to match the colum number.Also RTFM [url=http://uk.php.net/manual/en/function.mysql-fetch-row.php]http://uk.php.net/manual/en/function.mysql-fetch-row.php[/url] Quote Link to comment Share on other sites More sharing options...
master82 Posted September 5, 2006 Author Share Posted September 5, 2006 That works great!But is there a way I can assign the values using their fieldnames rather than a number?eg$user[username] (would show the username)rather than$user[1]is it possible? Quote Link to comment Share on other sites More sharing options...
Unknown User Posted September 5, 2006 Share Posted September 5, 2006 Err, i'm sure i do that.Add [quote]seesion_start();[/quote] at the top.Then, if you want their username for example.[quote]$_SESSION['username'][/quote] Quote Link to comment Share on other sites More sharing options...
zawadi Posted September 5, 2006 Share Posted September 5, 2006 [quote]Descriptionarray mysql_fetch_row ( resource result )Returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead.[/quote]to use mysql_fetch_objectthen use $user->username; 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.