Ken2k7 Posted August 18, 2007 Share Posted August 18, 2007 Say I have a database with a table named members with columns - id, member name, age etc.. Is there a way I can get the member name from the table members and store it in a variable $name without looping? Quote Link to comment https://forums.phpfreaks.com/topic/65634-getting-data-from-database/ Share on other sites More sharing options...
phpSensei Posted August 18, 2007 Share Posted August 18, 2007 You Want To Get All The Member Names or Just one..?? Quote Link to comment https://forums.phpfreaks.com/topic/65634-getting-data-from-database/#findComment-327788 Share on other sites More sharing options...
Ken2k7 Posted August 18, 2007 Author Share Posted August 18, 2007 Just 1 please. For example: I store the person's name into the database when they register but then I want to display that person's ID# when they log in. But I don't know how to pull just that one entry directly out of the database. Quote Link to comment https://forums.phpfreaks.com/topic/65634-getting-data-from-database/#findComment-327789 Share on other sites More sharing options...
hostfreak Posted August 19, 2007 Share Posted August 19, 2007 Straight from the manual (http://www.php.net/manual/en/function.mysql-fetch-assoc.php): // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } Look at comment line 2 Quote Link to comment https://forums.phpfreaks.com/topic/65634-getting-data-from-database/#findComment-327893 Share on other sites More sharing options...
phpSensei Posted August 19, 2007 Share Posted August 19, 2007 Once They Log in Just use this code here Login Page <?php session_start(); $_SESSION['user'] = $_POST['username'] // This Registeres That ONE username into a session called user, and $_POST is the username he entered from the form....// ?> Index Page <?php session_start(); $username=$_SESSION['user']; $query= mysql_query("SELECT * FROM username_table WHERE username = '$username'"); while($row=mysql_fetch_assoc($query)){ echo $row['username']; } ?> OR <?php $query= mysql_query("SELECT * FROM username_table WHERE id = 'The_Row_You_WANT'"); while($row=mysql_fetch_assoc($query)){ echo $row['username']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65634-getting-data-from-database/#findComment-328134 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.