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

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

}

?>

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.