Jump to content

Help with while loop


Recommended Posts



What im trying to do is show under each category some pictures...


I found this code and change it a little bit, but its still shows only one category and the images...


Any suggestions how im gonna change it to show all my category's?


<div id="PastProjects">Past Projects</div>

$query = mysql_query("SELECT * FROM tbl_pastprojects");

$counter = 0;//Use this as a way to ID data as it comes in.

while($row = mysql_fetch_assoc($query))
$catid[$counter] = $row['IssueId'];		
$catname[$counter] = $row['Title'];                

$NumTimes = count($catid); //Establishing a number of times to run the second loop
for($i=0; $i<=$NumTimes; $i++)
$query1 = mysql_query("SELECT * FROM tbl_pastprojects_entries WHERE IssueId = ".$catid[$i]."");

$c=0;//Another Counter for SubID's	
                while($row = mysql_fetch_assoc($query1))	
	$subid[$i][$c] = $row['Id'];		
	$sname[$i][$c] = $row['Thumb'];                                
//Now all of the Cats are stored in 2 Arrays(1 For name and 1 for ID) and SubCats are in 2 Multi Arrays(1 For name and 1 for ID)

///Generate Display
for($j=0; $j<$NumTimes; $j++)
echo("<div id='PastProjectstitle'>");
//Establish Count for  sub cats
$NumCats = count($subid[$j]);//This counts the second dimension of the array (which is the num of sub categorys for that particular category)
echo("<div id='PastProjectsImages'>");
//Loop through each SubCat
for($k=0; $k<$NumCats; $k++)
	echo("<img src='".$sname[$j][$k]."' />");



Link to comment
Share on other sites


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.