Cyder Posted January 10, 2007 Share Posted January 10, 2007 Im working on a gallery and I have 5 categories. At each object I set a category-number between 1-5. And when I loop all the objects out I would like to sort them by these numbers. The problem is I dont know how the "if" code is supposed to look. My guess is that It would look something like this below but the code doesnt work. Could anyone please help me sort this problem out?[code]$sql1 = "SELECT * FROM object ORDER BY pic DESC" or exit (mysql_error());$result1 = mysql_query($sql1);$r1 = mysql_fetch_array($result1); if ($r1['cat'] == '1') { echo '<div class="cat"><p id="cat1"><img src="-/0.gif"></p>'; while ($r1 = mysql_fetch_array($result1)) { echo '<a href="?X=F&Y='.$r1['pic'].'"><img src="-/'.$r1['pic'].'.gif" alt=" "></a>'; } echo '</div>'; } elseif ($r1['cat'] == '2') { echo '<div class="cat"><p id="cat2"><img src="-/0.gif"></p>'; while ($r1 = mysql_fetch_array($result1)) { echo '<a href="?X=F&Y='.$r1['pic'].'"><img src="-/'.$r1['pic'].'.gif" alt=" "></a>'; } echo '</div>'; } elseif ($r1['cat'] == '3') { echo '<div class="cat"><p id="cat3"><img src="-/0.gif"></p>'; while ($r1 = mysql_fetch_array($result1)) { echo '<a href="?X=F&Y='.$r1['pic'].'"><img src="-/'.$r1['pic'].'.gif" alt=" "></a>'; } echo '</div>'; } elseif ($r1['cat'] == '4') { echo '<div class="cat"><p id="cat4"><img src="-/0.gif"></p>'; while ($r1 = mysql_fetch_array($result1)) { echo '<a href="?X=F&Y='.$r1['pic'].'"><img src="-/'.$r1['pic'].'.gif" alt=" "></a>'; } echo '</div>'; } elseif ($r1['cat'] == '5') { echo '<div class="cat"><p id="cat5"><img src="-/0.gif"></p>'; while ($r1 = mysql_fetch_array($result1)) { echo '<a href="?X=F&Y='.$r1['pic'].'"><img src="-/'.$r1['pic'].'.gif" alt=" "></a>'; } echo '</div>'; }[/code] Link to comment https://forums.phpfreaks.com/topic/33583-categories/ Share on other sites More sharing options...
trq Posted January 10, 2007 Share Posted January 10, 2007 Sort them with your query, much easier and more efficient.[code]SELECT * FROM object ORDER BY cat_id DESC;[/code] Link to comment https://forums.phpfreaks.com/topic/33583-categories/#findComment-157314 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.