Loop Question
Posted: Thu Sep 10, 2009 11:16 pm
Hi every one.
I am trying to make a loop which can reduce HTML coding in my script. First here is what I am doing now: I will explain my script under /////
////more scripts.......
for($z=0; $z<$rowcount; $z++)
{
$queryP = sprintf("SELECT * From Post WHERE YMid ='$YMid' AND Catid ='$CatidP'");
$resultP = mysql_query($queryP);
$rowP = mysql_fetch_array($resultP);
/////////////////////////storing data in array for later use
$PS[] = $rowP ['PS'];///// PS may have upto 9 value control by $z
$Ex[] = $rowP ['Ex'];////////Ex may have upto 9 value control by $z
/////////////obtaining the Total
$PST = $PST + $PS[$z];
$ExT = $ExT + $Ex[$z];
}
///////////// result shown on the table
/////more scripts ........
////////////////////////////////////PS Data
echo "<td align='left' bgcolor='#FF9900'><font face='Tahoma' size='2' color='#FFFFFF'><b>";
echo "PS";
echo"</font></b></td>";
for($a=0; $a<$rowcount; $a++)
{
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'>";
echo "$$PS[$a]";
echo"</font></td>";
// this will cause to show all value of PS horizontally in the table
}
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'><b>";
echo "$$PST";
echo"</font></b></td>";
echo "</tr>";
////////////////////////////////////Ex Data
echo "<td align='left' bgcolor='#FF9900'><font face='Tahoma' size='2' color='#FFFFFF'><b>";
echo "Ex";
echo"</font></b></td>";
for($a=0; $a<$rowcount; $a++)
{
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'>";
echo "$$Ex[$a]";
echo"</font></td>";
// this will cause to show all value of Ex horizontally in the table
}
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'><b>";
echo "$$ExT";
echo"</font></b></td>";
echo "</tr>";
The above script is working just fine. However my problem is that I have around more than 25 variable like $PS[] and $Ex[], each contains upto 9 variable values. So I have to set up 25 times or so the above HTML script to show the data in the table. That's make awfully long script. I am thinking there got to be any function which can hold these 25 x 9 variables. Which can be control by two "for loops" one with 25 value and other 9 values
Any help?
Thanks for your time.
I am trying to make a loop which can reduce HTML coding in my script. First here is what I am doing now: I will explain my script under /////
////more scripts.......
for($z=0; $z<$rowcount; $z++)
{
$queryP = sprintf("SELECT * From Post WHERE YMid ='$YMid' AND Catid ='$CatidP'");
$resultP = mysql_query($queryP);
$rowP = mysql_fetch_array($resultP);
/////////////////////////storing data in array for later use
$PS[] = $rowP ['PS'];///// PS may have upto 9 value control by $z
$Ex[] = $rowP ['Ex'];////////Ex may have upto 9 value control by $z
/////////////obtaining the Total
$PST = $PST + $PS[$z];
$ExT = $ExT + $Ex[$z];
}
///////////// result shown on the table
/////more scripts ........
////////////////////////////////////PS Data
echo "<td align='left' bgcolor='#FF9900'><font face='Tahoma' size='2' color='#FFFFFF'><b>";
echo "PS";
echo"</font></b></td>";
for($a=0; $a<$rowcount; $a++)
{
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'>";
echo "$$PS[$a]";
echo"</font></td>";
// this will cause to show all value of PS horizontally in the table
}
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'><b>";
echo "$$PST";
echo"</font></b></td>";
echo "</tr>";
////////////////////////////////////Ex Data
echo "<td align='left' bgcolor='#FF9900'><font face='Tahoma' size='2' color='#FFFFFF'><b>";
echo "Ex";
echo"</font></b></td>";
for($a=0; $a<$rowcount; $a++)
{
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'>";
echo "$$Ex[$a]";
echo"</font></td>";
// this will cause to show all value of Ex horizontally in the table
}
echo "<td align='right' bgcolor='#C0C0C0'><font face='Tahoma' size='2'><b>";
echo "$$ExT";
echo"</font></b></td>";
echo "</tr>";
The above script is working just fine. However my problem is that I have around more than 25 variable like $PS[] and $Ex[], each contains upto 9 variable values. So I have to set up 25 times or so the above HTML script to show the data in the table. That's make awfully long script. I am thinking there got to be any function which can hold these 25 x 9 variables. Which can be control by two "for loops" one with 25 value and other 9 values
Any help?
Thanks for your time.