Greetings...this may be obvious to all, but has stumped me. The code Im trying to get working is below. The problem is, the newsarray variable seems to live only in the first foreach() iteration. If I try I add another level to the code (after the initial foreach), I lose access to foreach as an array. I get only one answer...the last.
Can somebody please let me know what Im doing wrong? I've read the php man page on variable scope (hence the global declaration...). Any news would be appreciated. Hit me here and at mailto://egomaniac1992@hotmail.com
thanks!
$numpage = ($numrows / 3);
$x = 0;
echo("numpage: ($numpage) numrows: ($numrows)<br>\n");
while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
{
foreach($row as $index => $value)
{
global $newsarray,$x;
$newsarray[$index] = $value;
} // end foreach
$x++;
echo("<tr class=\"red\"><td>Author</td><td>Article Size </td><td>Date</td><td>Details</td>");
buildPage($newsarray,$numpage,$numrows,$x);
} // end while
echo("</table><br>");
function buildPage($newsarray,$numpage,$numrows,$x)
{
while($numpage > 0) {
echo("numpage: ($numpage), numrows: ($numrows) x: ($x) <br>\n");
if ( ($numrows > 0) && ($numrows <= 3)) {
for ($i=1; $i <= 3; $i++) {
echo("newsarray: ($newsarray)<br>\n");
echo("<tr class=\"red\"><td>Author</td><td>Article Size</td><td>Date</td><td>Details</td>");
printArray($newsarray);
}//end for
exit();
}//end while
$numpage = $numpage - 1;
$numrows = $numrows - 3;
}//end buildPage($newsarray,$numpage,$numrows)
function printArray($newsarray)
{
//echo("in printarray($newsarray)<br>\n");
$array = $newsarray;
echo("<tr><td><strong>" . $array['author'] . "</strong></td><td>" . $array['size']. "<td>" . $array['date'] . "</td><td><a href='http://www.winnipegbeach.com/elektrus/inews.php?id=" . $newsarray['id'] . "'>Full Article</a></td></tr>\n");
echo("<tr><td colspan=\"4\">" . $array['preview'] . "</td></tr><tr><td colspan=\"4\"> </td>\n");
}//end function printArray