Jump to content

Getting data from database


Ken2k7

Recommended Posts

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

Link to comment
Share on other sites

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'];

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.