Jump to content

seconde loop empty


drisate

Recommended Posts

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

Link to comment
Share on other sites

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++;
} 	
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.