Hi everyone,
Nesting loops to create html tables with (incremented) variable names is a task I am weak at.
What I have is a quiz that lists each person in a row then shows the next name in the next row.
I could not figure out how to loop thru this, so I did it all by hand (I know, php would be more efficient, but I could not get it to work).
Here is my page showing what it looks like...
My HTMl/php way of doing it.
I actually did the form by hand also.
My HTML form with N[0] N[1] etc for the names.
The code for the query is. ( I shortened this, it si actually 45 names long!)
//get get the names of the celebs from the Names table
$query="SELECT * FROM QRatingNames";
$result=mysql_query($query);
while ($myrow = mysql_fetch_array($result))
{
$Celeb00 = $myrow['Name0'];
$Celeb01 = $myrow['Name1'];
//etc all the way to 45
}
Heres the query to get the votes ... (Again, I had to do this 45 times!)
//Get Name0
$query0="SELECT COUNT(*) FROM QRatingVotes WHERE Name0='1' AND QRatingID='1'";
$result=mysql_query($query0);
$num=mysql_fetch_row($result);
$Name00 = $num[0];
$query0="SELECT COUNT(*) FROM QRatingVotes WHERE Name0='2' AND QRatingID='1'";
$result=mysql_query($query0);
$num=mysql_fetch_row($result);
$Name01 = $num[0];
$query0="SELECT COUNT(*) FROM QRatingVotes WHERE Name0='3' AND QRatingID='1'";
$result=mysql_query($query0);
$num=mysql_fetch_row($result);
$Name02 = $num[0];
$query0="SELECT COUNT(*) FROM QRatingVotes WHERE Name0='4' AND QRatingID='1'";
$result=mysql_query($query0);
$num=mysql_fetch_row($result);
$Name03 = $num[0];
$query0="SELECT COUNT(*) FROM QRatingVotes WHERE Name0='5' AND QRatingID='1'";
$result=mysql_query($query0);
$num=mysql_fetch_row($result);
$Name04 = $num[0];
$QRatings = ($Name00/$totalcount)*100;
$Total1 = round($QRatings,2);
$NameTotal0 = $Total1 . '%';
//Get Name1
And then to build the table... (45 times, note: I alternated cell colors for ease of reading)
//ROW 0
echo '<tr><p class="fontbold"><td width="150" class="fontbold">'.$Celeb00.'</td></p><td width="100" class="fontred">'.$Name00.'</td><td width="100" class="fontred">'.$Name01.'</td><td width="100" class="fontred">'.$Name02.'</td><td width="100" class="fontred">'.$Name03.'</td><td width="100" class="fontred">'.$Name04.'</td<td width="100" class="fontred">'.$totalcount.'</td><td width="100" class="fontred">'.$NameTotal0.'</td></tr>';
//ROW 1
echo '<tr><td width="150" bgcolor="#CCCCCC" class="fontbold">'.$Celeb01.'</td><td width="100" bgcolor="#CCCCCC" class="fontred">'.$Name10.'</td><td width="100" bgcolor="#CCCCCC" class="fontred">'.$Name11.'</td><td width="100" bgcolor="#CCCCCC" class="fontred">'.$Name12.'</td><td width="100" bgcolor="#CCCCCC" class="fontred">'.$Name13.'</td><td width="100" bgcolor="#CCCCCC" class="fontred">'.$Name14.'</td<td width="100" bgcolor="#CCCCCC" class="fontred">'.$totalcount.'</td><td width="100" bgcolor="#CCCCCC" class="fontred">'.$NameTotal1.'</td></tr>';
I am looking for any suggestions to simplify these with loops. I read thru dozens of posts and could apply what I read, so I pounded thru it the hard way.
Now I am looking to learn the correct way.
Thanks,
Don