User profiles

Ask about a PHP problem here.
Post Reply
kpkguru003
Posts: 14
Joined: Fri Nov 11, 2011 12:32 pm
Location: India

User profiles

Post 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 ?
kpkguru003
Posts: 14
Joined: Fri Nov 11, 2011 12:32 pm
Location: India

Re: User profiles

Post by kpkguru003 »

[syntax=php]<?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>[/syntax]
Last edited by jacek on Mon Dec 26, 2011 2:55 pm, edited 1 time in total.
Reason: code tags...
bowersbros
Posts: 534
Joined: Thu May 05, 2011 8:19 pm

Re: User profiles

Post by bowersbros »

Please edit your post and use the code tag button

[syntax=php][syntax=php ][/syntax ][/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.

[syntax=sql]SELECT * FROM users WHERE id = $id[/syntax]

It is also worth noting that SELECT * (All) is bad technique, you should only select the fields that are necessary for you.

Eg. [syntax=sql]SELECT `id`,`username`,`email` FROM `users` WHERE `id` = '{$_POST['id']}'[/syntax]
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ;)

Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Post Reply