herghost Posted February 26, 2009 Share Posted February 26, 2009 Hi All, I am trying to display data from a mysql table in PHP, the idea is the user can see information about themselves when they click on a link and change various things. This is what I have so far: <?php require_once('dbconfig.php'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } mysql_select_db(DB_DATABASE); //select the table $result = mysql_query("select * from members"); //grab all the content while($r=mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"]; //modify these to match your mysql table columns $firstname=$r["firstname"]; $lastname=$r["lastname"]; $login=$r["login"]; $email=$r["email"]; //display the row echo "<br /> <br /> <br /> <br /> Your First Name: $firstname <br> Your Surname: $lastname <br> Your Username: $login <br> Your Email Address: $email "; } ?> Which works fine apart from one minor detail, It displays everything in the database How can I change this just to display the users information? Each user is assigned a auto increment primary id in the database. Thanks Link to comment https://forums.phpfreaks.com/topic/147077-data-from-mysql-database/ Share on other sites More sharing options...
revraz Posted February 26, 2009 Share Posted February 26, 2009 Use a Session to store the user's ID and then change your SELECT to add a WHERE clause and include that ID. Link to comment https://forums.phpfreaks.com/topic/147077-data-from-mysql-database/#findComment-772137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.