Display by ID number

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daebat
Forum Commoner
Posts: 47
Joined: Mon May 11, 2009 10:16 am

Display by ID number

Post by daebat »

I have data that is uploaded from a custom built back-end inserted with id numbers auto-incremented. The code below will successfully show one entry but how can I get it to display all entries in order (by id number)?

Code: Select all

<div id="content">
<?php
 
mysql_connect("localhost", "user", "pw") or die(mysql_error()) ;
mysql_select_db("db") or die(mysql_error()) ;
 
?>
<div>
<h1>Print Ads<hr /></h1><br />
<?php
$data = mysql_query("SELECT * FROM printads") or die(mysql_error());
 
 
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
Echo "<div style='float:left;'>";
Echo "<table width='225'>";
Echo "<tr><td colspan='2' style='text-align:center;text-transform:uppercase;'><b> ".$info['title'] . "</b></td></tr> ";
Echo "<tr><td colspan='2' style='text-align:center;'><b> ".$info['title2'] . "</b></td></tr> ";
Echo "<tr><td colspan='2' style='text-align:center;'><a href='upload/2010printads/".$info['image'] ."'><img src='upload/2010printads/".$info['thumb'] . "' style='text-align:center;'></a></td></tr>";
Echo "<tr><td style='vertical-align: middle; text-align:center;font-size:x-small;'>Color Illustrator Vector EPS</td><td><a href='upload/2010printads/".$info['eps1'] . "'><img src='../associates/images/download.png' border='0' width='75'></a><br></td></tr>";
Echo "<tr><td style='vertical-align: middle; text-align:center;font-size:x-small;'>Color Press Quality PDF</td><td><a href='upload/2010printads/".$info['pdf1'] . "'><img src='../associates/images/download.png' border='0' width='75'></a><br></td></tr>";
Echo "<tr><td style='vertical-align: middle; text-align:center;font-size:x-small;'>B&W Illustrator Vector EPS</td><td><a href='upload/2010printads/".$info['eps2'] . "'><img src='../associates/images/download.png' border='0' width='75'></a><br></td></tr>";
Echo "<tr><td style='vertical-align: middle; text-align:center;font-size:x-small;'>B&W Press Quality PDF</td><td><a href='upload/2010printads/".$info['pdf2'] . "'><img src='../associates/images/download.png' border='0' width='75'></a><br></td></tr>";
 
Echo "</table>";
Echo "</div>";
 
 
}
?> 
</div>
 
</div>
 
</div>
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Display by ID number

Post by social_experiment »

Code: Select all

 
$data = mysql_query("SELECT * FROM printads ORDER BY id ASC ") or die(mysql_error());
 
If you want the items to be displayed ascending ( 0 - highest value ), and

Code: Select all

 
$data = mysql_query("SELECT * FROM printads ORDER BY id DESC") or die(mysql_error());
 
for descending ( highest value - 0 ).
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
daebat
Forum Commoner
Posts: 47
Joined: Mon May 11, 2009 10:16 am

Re: Display by ID number

Post by daebat »

Thank you!
Post Reply