loganbest Posted April 8, 2006 Share Posted April 8, 2006 I have been trying to get stuff to display on a page in a certain order from a DB. I have the connection done and keep meesing up the queries and the display looping.Table name: magazinesColumn: issue_idColumn: titleColumn: num_of_articlesI need it to display in order of Issue IDCan anyone help? Link to comment https://forums.phpfreaks.com/topic/6912-getting-stuff-from-mysql-db-and-looping-a-display/ Share on other sites More sharing options...
IceHawk Posted April 9, 2006 Share Posted April 9, 2006 The basic query you're looking for is;select * from magazines order by issue_id asc orselect * from magazines order by issue_id descThe first will order the results on issue_id is ascending order, the second in descending order. Link to comment https://forums.phpfreaks.com/topic/6912-getting-stuff-from-mysql-db-and-looping-a-display/#findComment-25135 Share on other sites More sharing options...
loganbest Posted April 9, 2006 Author Share Posted April 9, 2006 Yea I realized what I was doing wrong about 10 minutes after I posted this. For anyone else who had this similar question, here is my code:[code]total magazines created: <b> <? db_connect(); $result=mysql_query("SELECT * FROM magazines"); $num_rows = mysql_num_rows($result); echo $num_rows; if ($num_rows == "0"){ echo '<h1>There are no Magazines!</h1><br><br>'; } else if (!$num_rows == "0"){ //MySQL Query to get the data $sql = mysql_query("SELECT * FROM magazines ORDER BY issue_id ASC") or die (mysql_error()); //prints the table echo '<br><br><table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td><b>Magazine Name</b></td> <td width="100"><b># of Articles</b></td> </tr>'; // keeps getting the next row until there are no more to getwhile ($row = mysql_fetch_array($sql)) {// Print out the contents of each row into a tableecho "<tr><td>";echo $row['title'];echo "</td><td>";echo $row['num_of_art'];echo "</td></tr>";}echo "</table>"; } ?> </b>[/code] Link to comment https://forums.phpfreaks.com/topic/6912-getting-stuff-from-mysql-db-and-looping-a-display/#findComment-25141 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.