Jump to content

Categories?


Cyder

Recommended Posts

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

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.