-4

i have this specific question to do to you,

i have a database from which i extract the information and my output is the name of the user and the photo of the user.

What i need to do is that when i click the user name i am redirected to another php file which which holds all information for this particular user.

The user is extracted like this:

$sql =" select * from hostess";
$query = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>FIRSTNAME</th>
<th>PHOTO</th>
</tr>";

while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row['first_name_en'] . "</td>";
"<td> <img src=upproject/foto/photo1".$row['photo'] . "
></td>";
"</tr>";
}
echo"</table>";
4

3 回答 3

0

try something like:

while ($row = mysql_fetch_array($query))
{
    echo "<tr>";
    echo "<td> <a href='infopage.php?id=".$row['id']."'>" . $row['first_name_en'] . "</a></td>";
    echo "<td> <img src=upproject/foto/photo1".$row['photo'] . "></td>";
    echo "</tr>";
}
于 2012-06-19T11:20:40.677 回答
0

You could change this line

echo "<td>" . $row['first_name_en'] . "</td>";

with one like this

echo '<td><a href="yournewpage.php?userid='.$row['userid'].'">'. 
     $row['first_name_en']."</a></td>";

where userid is database-associated user id.
Naturally in the page you are redirected you need to get $_GET['userid'] and retrieve database data associated to this.
Be careful: sanitize user input, always, to avoid sql-injection!

于 2012-06-19T11:21:25.340 回答
0

Add a link/href around the photo that the next php (or the same one with some conditional checking) page can use to display information using an ID to query the database like this:

while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td><a href='somephpfile.php?ID=".$row['ID']."'>" . $row['first_name_en'] . "</a></td>";
"<td><img src=upproject/foto/photo1".$row['photo'] . "></td>";
"</tr>";
}
echo"</table>";
于 2012-06-19T11:22:04.703 回答