Page 1 of 1

User profiles

Posted: Mon Dec 26, 2011 1:58 pm
by kpkguru003
if i clicked any name(link) from the user list , it ll show only the profile which contains the last row details in the database.
if i clicked the link of id=1 it will open the last id's profile !!!!!!!!!!!!!!

how to get the solution for this ?

Re: User profiles

Posted: Mon Dec 26, 2011 2:04 pm
by kpkguru003
<?php
include 'connect.php';
       $query = mysql_query("SELECT * FROM student");
       $numrows = mysql_num_rows($query);
           if($numrows > 0) {
    	 while ($row = mysql_fetch_assoc($query)){
       		   $id = $row['id'];
       		   $regno = $row['regno'];
       		   $name = $row['name'];
	}
    	}
?>   	 		
<html>
<head>
<title><?php echo $name; ?>'s profile</title>
</head>
<body>
  <div id="container">
	<h1><?php echo $name; ?>'s profile</h1>
	<table>
	<tr><td>RegNo : <?php echo $regno; ?></td></tr>
	<tr><td>Name : <?php echo $name; ?></td></tr>
</div>
</body>
</html>

Re: User profiles

Posted: Mon Dec 26, 2011 2:13 pm
by bowersbros
Please edit your post and use the code tag button
[syntax=php ][/syntax ]
Thanks.

Also, The reason is because you dont use any conditional operators in your SQL statement.

You need to tell it WHERE to look,

Change your query to accomodate for that.
SELECT * FROM users WHERE id = $id
It is also worth noting that SELECT * (All) is bad technique, you should only select the fields that are necessary for you.

Eg.
SELECT `id`,`username`,`email` FROM `users` WHERE `id` = '{$_POST['id']}'