drisate Posted March 5, 2008 Share Posted March 5, 2008 Hey guys. I made a function that builds up a list of categories. A few have images and a few don't ... so for estetic reasons i made a loop that gets all the categories with images in loop 1 and all of them with out in loop 2 <?php function list_categ() {$i=1; while ($i < 2){ if ($i==1){$where="and cat_img!=''";}else{$where="and cat_img=''";} if ($_GET[cat_]==""){$_GET[cat_]=0;} $command = mysql_query("Select * FROM categories where parent_cat_id='$_GET[cat_]' $where order by cat_name") or die (mysql_error()); while ($data = mysql_fetch_array($command)) { $tablo[]=$data; } if ($_GET[cat_]=="0" or $_GET[cat_]=="" or ($i=="1")){$numcols=4;}else{$numcols=2;} $data = range(0,count($tablo) - 1); $numrows = ceil (count($data)/$numcols); echo '<table align="center" width="80%">'; for ($r=0; $r<$numrows; $r++) { echo '<tr>'; for ($c=0; $c<$numcols; $c++) { $cell = isset($data[$r + $c*$numrows]) ? $data[$r + $c*$numrows] : ' '; if ($tablo[$cell]['cat_img']!=""){ print ('<td> <table border="0" cellpadding="3" cellspacing="3" width="100%"> <tr> <td><center><a href="index.php?mod=6&cat_='.$tablo[$cell]['cat_id'].'"><img border="0" src="admin/image/categ/thumbs/'.$tablo[$cell]['cat_img'].'"></a></center></td> </tr> <tr> <td><center><a href="index.php?mod=6&cat_='.$tablo[$cell]['cat_id'].'">'.$tablo[$cell]['cat_name'].'</a></center></td> </tr> </table> </td>'); }else{ print ('<td><a href="index.php?mod=6&cat_='.$tablo[$cell]['cat_id'].'">'.$tablo[$cell]['cat_name'].'</a></td>'); } } echo '</tr>'; } echo '</table>'; if ($i==1){echo "<br><br>";} $i++; } } ?> What did i miss? page is at http://www.trans-f-air.com/EZA/index.php?mod=6&cat_=37 Quote Link to comment https://forums.phpfreaks.com/topic/94396-seconde-loop-empty/ Share on other sites More sharing options...
drisate Posted March 5, 2008 Author Share Posted March 5, 2008 no idea why the code appeared like that but let me repost it <?php function list_categ() {$i=1; while ($i < 2){ if ($i==1){$where="and cat_img!=''";}else{$where="and cat_img=''";} if ($_GET[cat_]==""){$_GET[cat_]=0;} $command = mysql_query("Select * FROM categories where parent_cat_id='$_GET[cat_]' $where order by cat_name") or die (mysql_error()); while ($data = mysql_fetch_array($command)) { $tablo[]=$data; } if ($_GET[cat_]=="0" or $_GET[cat_]=="" or $i=="1"){$numcols=4;}else{$numcols=2;} $data = range(0,count($tablo) - 1); $numrows = ceil (count($data)/$numcols); echo '<table align="center" width="80%">'; for ($r=0; $r<$numrows; $r++) { echo '<tr>'; for ($c=0; $c<$numcols; $c++) { $cell = isset($data[$r + $c*$numrows]) ? $data[$r + $c*$numrows] : ' '; if ($tablo[$cell]['cat_img']!=""){ print ('<td> <table border="0" cellpadding="3" cellspacing="3" width="100%"> <tr> <td><center><a href="index.php?mod=6&cat_='.$tablo[$cell]['cat_id'].'"><img border="0" src="admin/image/categ/thumbs/'.$tablo[$cell]['cat_img'].'"></a></center></td> </tr> <tr> <td><center><a href="index.php?mod=6&cat_='.$tablo[$cell]['cat_id'].'">'.$tablo[$cell]['cat_name'].'</a></center></td> </tr> </table> </td>'); }else{ print ('<td><a href="index.php?mod=6&cat_='.$tablo[$cell]['cat_id'].'">'.$tablo[$cell]['cat_name'].'</a></td>'); } } echo '</tr>'; } echo '</table>'; if ($i==1){echo "<br><br>";} $i++; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/94396-seconde-loop-empty/#findComment-483472 Share on other sites More sharing options...
drisate Posted March 5, 2008 Author Share Posted March 5, 2008 Found it ... while ($i <= 2) lol Quote Link to comment https://forums.phpfreaks.com/topic/94396-seconde-loop-empty/#findComment-483485 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.