I'm building a gallery script and I'm having trouble with it. The problem section of the script uses 2 tables from the database : gall_sections, and gall_albums. The idea being that user named albums of photos are to be stored in user named sections.
Each row of the gall_sections table has a unique number in the 'sec_id' coloumn. There is also a 'sec_id' coloumn in gall_albums which identifies each of those albums with the section that it is in.
The result of the script ( after a lot more code) is that the albums are returned to the browser as groups of javascript arrays. One array for each section.
I have a for loop that loops through the gall_sections results that is working as I want it to , and a for loop within that loop that loops through the gall_albums results which is not working properly.
I'll post up the code without all the comments if it's any help.
At the moment there are 3 sections, and 3 albums with 1 album in each section.
What I'm looking for is for the loop to return the number of albums in each section.
$numalb1=1
$numalb2=1
$numalb3=1
At the moment, at end of the cycles of the outer loop, all $numalb variables are equal to 3.
Can anyone see what I'm doing wrong here?
Each row of the gall_sections table has a unique number in the 'sec_id' coloumn. There is also a 'sec_id' coloumn in gall_albums which identifies each of those albums with the section that it is in.
The result of the script ( after a lot more code) is that the albums are returned to the browser as groups of javascript arrays. One array for each section.
I have a for loop that loops through the gall_sections results that is working as I want it to , and a for loop within that loop that loops through the gall_albums results which is not working properly.
Code:
[COLOR=red yellow]//get all the results from gall_sections[/color]
$secquery="select * from gall_sections
order by sec_id";
$secresult=mysql_query($secquery);
$numrows1=mysql_num_rows($secresult);
[COLOR=red yellow]// If there are sections defined:[/color]
if(!empty($numrows1))
{
[COLOR=red yellow]//get all the results from gall_albums[/color]
$getalbs_query="select * from gall_albums";
$getalbs_result=mysql_query($getalbs_query);
$albs_numrows=mysql_num_rows($getalbs_result);
[COLOR=red yellow]//echo the start point of the javascript:[/color]
echo '<script>';
[COLOR=red yellow]//The first loop starts here, works as it should:[/color]
for($e=0;$e<$numrows1;$e++)
{
$row=mysql_fetch_array($secresult);
$secvar=$row['sec_id'];
echo 'var section'.$secvar.'=array(\'';
[COLOR=red yellow]//second loop
//Each section will return the variable $numbalb appended
//with that sections 'sec_id' number. The variable should
//equal the number of albums in that section[/color]
for($b=0;$b<$albs_numrows;$b++)
{
$row2=mysql_fetch_array($getalbs_result);
$albvar=$row2['sec_id'];
[COLOR=red yellow]//if the sec_id in gall_albums and gall_sections is the same[/color]
if($albvar = $secvar)
{
[COLOR=red yellow]//if this variable isn't set then create it and give it the value 0[/color]
if(!isset(${numalb.$secvar}))
{
${numalb.$secvar}=0;
}
[COLOR=red yellow]//add one to the variable[/color]
${numalb.$secvar}+=1;
}
}
[COLOR=red yellow]//reset the gall_albums result array pointer back to the start of the array [/color]
mysql_data_seek($getalbs_result,0);
}
}
?>
At the moment there are 3 sections, and 3 albums with 1 album in each section.
What I'm looking for is for the loop to return the number of albums in each section.
$numalb1=1
$numalb2=1
$numalb3=1
At the moment, at end of the cycles of the outer loop, all $numalb variables are equal to 3.
Can anyone see what I'm doing wrong here?