Jump to content

PHP/MySQL Select by ID, select information from that row.


xtrafile

Recommended Posts

I couldn't really find this anywhere, but I am making one page, which will select data from a MySQL table to print.

 

According to this ID set up by switch() (if that's the best way to do it), PHP should select that ID from MySQL and print out ,say the First Name as related to the ID.

 

To further explain, below is the code I have to actually get data form the database.

 

$sql = "SELECT * FROM `ROW` " or die(mysql_error());  
$query = mysql_query($sql);
while($ROW= mysql_fetch_object($query)) 
{
echo "<tr>
<td><div align='center'>" . $ROW->name . "</div></td>
        </tr>
";
}

 

The code does not select that name based on ID however.

 

How could I accomplish this task?

 

Thanks!

Try this:

 

<?php
$sql = "SELECT * FROM `ROW` WHERE `id` = '$id' " or die(mysql_error());  
$query = mysql_query($sql);
while($arr= mysql_fetch_assoc($query) )
{
extract($arr);
echo "<tr>
<td><div align='center'>$name</div></td>
        </tr>
";
}
?>

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.