xtrafile Posted April 4, 2008 Share Posted April 4, 2008 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! Link to comment https://forums.phpfreaks.com/topic/99612-phpmysql-select-by-id-select-information-from-that-row/ Share on other sites More sharing options...
p2grace Posted April 4, 2008 Share Posted April 4, 2008 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> "; } ?> Link to comment https://forums.phpfreaks.com/topic/99612-phpmysql-select-by-id-select-information-from-that-row/#findComment-509594 Share on other sites More sharing options...
xtrafile Posted April 5, 2008 Author Share Posted April 5, 2008 That'll do it! Thanks Link to comment https://forums.phpfreaks.com/topic/99612-phpmysql-select-by-id-select-information-from-that-row/#findComment-509727 Share on other sites More sharing options...
p2grace Posted April 5, 2008 Share Posted April 5, 2008 Hey, Glad I could help... could you mark the topic as solved. Thank you Link to comment https://forums.phpfreaks.com/topic/99612-phpmysql-select-by-id-select-information-from-that-row/#findComment-509987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.