Jump to content

getting stuff from MySQL DB and looping a display


loganbest

Recommended Posts

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: magazines
Column: issue_id
Column: title
Column: num_of_articles

I need it to display in order of Issue ID


Can anyone help?
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 get
while ($row = mysql_fetch_array($sql)) {

// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['title'];
echo "</td><td>";
echo $row['num_of_art'];
echo "</td></tr>";
}
echo "</table>";
      }
       ?> </b>[/code]

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.