terryhawkins Posted January 15, 2008 Share Posted January 15, 2008 I have this PHP script which has been copied from a server running an older version of PHP to a new server with a new version, for some reason the table display will not work. It is reading from the database fine, and I cannot see what's wrong... Please can someone help me, here's the code. It seems like a problem with the 'foreach' part: <?PHP require("../admin/global.php"); $numToDisp = 1000; # the max number of post to show per page $numOfColumnsSec = 4; # the number of sections to list per row if(!$start) $start = 0; $link = mysql_connect($serverName, $serverUsr, $serverPass) or die ("Could not connect<br>"); mysql_select_db ($serverDb, $link) or die ("Could not select database<br>"); ###### sections display $sections = array(); $sql = "SELECT section FROM stowmarket WHERE display = 'yes' ORDER BY news_date"; $results=mysql_query($sql, $link); while($result = mysql_fetch_array($results,$link)){ array_push($sections,trim($result['section'])); } $sections = array_unique($sections); $counter = 0; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Stowmarket Golf Club - Results</title> <link href="http://www.club-noticeboard.co.uk/stowmarket/styles.css" rel="stylesheet" type="text/css"> </head> <body> <div align="center"> <table width="760" border="0" cellpadding="0" cellspacing="0" bgcolor="#00CC65" class="topcell-sidebars"> <tr> <td><div align="center"><img src="http://www.club-noticeboard.co.uk/stowmarket/images/topimage.gif" width="405" height="120"><img src="http://www.club-noticeboard.co.uk/stowmarket/images/titlebar.gif" width="353" height="120"></div></td> </tr> </table> <table width="760" border="0" cellpadding="0" cellspacing="0" class="navbar"> <tr> <td><div align="center" class="navfont"><a href="http://www.club-noticeboard.co.uk/stowmarket/index.htm" class="navfont">Home</a> <a href="secretary.php" class="navfont">Secretary</a> <a href="calendar.php" class="navfont">Calendars</a> <a href="results.php" class="navfont">Results</a> <a href="http://www.club-noticeboard.co.uk/stowmarket/clubhouse.htm" class="navfont">Clubhouse</a> <a href="http://www.club-noticeboard.co.uk/stowmarket/proshop.htm" class="navfont">Proshop</a> <a href="http://www.club-noticeboard.co.uk/stowmarket/holebyhole.htm" class="navfont">Hole By Hole</a> <a href="http://www.club-noticeboard.co.uk/stowmarket/analysis.htm" class="navfont">Free Golf Analysis</a> <a href="http://www.club-noticeboard.co.uk/stowmarket/centenary.htm" class="navfont">Centenary Reports</a> <a href="http://www.club-noticeboard.co.uk/stowmarket/contacts.htm" class="navfont">Contacts</a> <a href="http://www.club-noticeboard.co.uk/stowmarket/opencomps.htm" class="navfont">Open Comps</a></div></td> </tr> </table> <table width="760" border="0" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#00CC65" class="maincell"><div align="left" class="TitleFont"> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td><table width="100%" cellpadding="0" cellspacing="0"> <tr> <td height="64" valign="top"><div align="left"> <p>Stowmarket Golf Club - Results <?php if($S!=""){ echo " - "; echo $S; }?> </p> <p> </p> <p><span class="MainTextFont">Click on a month below to view the results: </span> </p> </div> </td> <td><div align="right"><img src="http://www.club-noticeboard.co.uk/stowmarket/images/title_results.gif" width="240" height="70" class="PictureBorder"></div></td> </tr> </table></td> </tr> </table> <p> </p> <table width="100%" border="0" cellpadding="4" cellspacing="1"> <tr> <?PHP foreach ($sections as $section){ $counter++; ?> <td width="25%" class="ResBox"><a class="MainTextFont" href="<?PHP echo $PHP_SELF."?S=".urlencode($section); ?>"> <?PHP echo $section; ?></a></td> <?PHP if($counter/$numOfColumnsSec == intval($counter/$numOfColumnsSec)){ ?> </tr> <tr> <?PHP } } ?> </tr> </table> <p align="center" class="MainTextFont"> </p> <p align="center" class="MainTextFont"><a href="http://www.club-noticeboard.co.uk/stowmarket/archive.htm" class="MainTextFont"></a> </p> <p align="center" class="MainTextFont"> </p> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td class="ResBox"><div align="center"><img src="http://www.club-noticeboard.co.uk/stowmarket/images/support100left.gif" width="127" height="100" border="0"> <iframe src="http://www.club-noticeboard.co.uk/admanagement/local/display.php?show_ad=6" marginheight="0" marginwidth="0" scrolling="no" frameborder="0" width="400" height="100" style="border:solid; border-color:#000000; border-width:1px"></iframe> <img src="http://www.club-noticeboard.co.uk/stowmarket/images/support100right.gif" width="127" height="100"></div></td> </tr> </table> <p align="center" class="MainTextFont"><A href="http://www.fredolsencruiselines.co.uk/" target=new_page></A></p> <p align="center" class="MainTextFont"> </p> <p align="center" class="MainTextFont"><strong>NEW!</strong><BR> <strong><A href="http://www.club-noticeboard.co.uk/results.htm">Suffolk Winter Alliance Results & News<BR> </A></strong>brought to you by Club-Noticeboard</p> <p align="left" class="MainTextFont"> <?PHP ###### news display $sql = "SELECT num FROM stowmarket"; $results=mysql_query($sql, $link); if (!(mysql_errno()==0)) { echo $sql."<br>\n"; echo mysql_errno().": ".mysql_error()."<BR>\n"; } $totalNews = mysql_num_rows($results); $sql = "SELECT * FROM stowmarket WHERE display = 'yes' AND section LIKE '$S' ORDER BY news_date DESC LIMIT $start, $numToDisp"; $results=mysql_query($sql, $link); if (!(mysql_errno()==0)) { echo $sql."<br>\n"; echo mysql_errno().": ".mysql_error()."<BR>\n"; } else{ ?> <?PHP $counter = 0; while($result = mysql_fetch_array($results)){ ?></p> <table width="100%" border="0" cellpadding="4" cellspacing="1" class="ResBox2"> <tr> <td class="ResBox3"> <?PHP echo $result['title']; ?> - <?PHP echo date("jS F Y",$result['news_date']) ?> </td> </tr> <br> <br> <tr> <td bgcolor=""><table width="100%" border="0" cellspacing="0" cellpadding="1"> <TR> <TD><?PHP echo stripslashes($result['news']); ?> <tr> <td> <?PHP $sql = "SELECT * FROM link_table WHERE client_id LIKE '".$result['when_created']."' AND section = 'news' ORDER BY title"; $results2=mysql_query($sql, $link); if (mysql_num_rows($results2) != 0) { while($result2 = mysql_fetch_array($results2)){ ?> <li><a href="<?PHP echo $result2['url']; ?>"> <?PHP echo $result2['title']; ?> </a> <?PHP echo $result2['description']; ?> </li> <?PHP } } ?> </table></td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0" height="6"> <tr> <td></td> </tr> </table> <?PHP } ?> </div> <p align="center"> </p> <table width="100%" cellpadding="0" cellspacing="0"> <tr> <td class="ResBox"><div align="center"><img src="http://www.club-noticeboard.co.uk/stowmarket/images/support100left.gif" width="127" height="100" border="0"> <iframe src="http://www.club-noticeboard.co.uk/admanagement/local/display.php?show_ad=7" marginheight="0" marginwidth="0" scrolling="no" frameborder="0" width="400" height="100" style="border:solid; border-color:#000000; border-width:1px"></iframe> <img src="http://www.club-noticeboard.co.uk/stowmarket/images/support100right.gif" width="127" height="100"></div></td> </tr> </table> <p align="center"> </p> <p align="center"> </p> <p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b><font color="#ffffff"><a class="type1" href="http://www.club-noticeboard.co.uk">::: SITE BUILT AND HOSTED BY CNB ::: PROVIDER OF FREE WEBSPACE, FREE HOSTING AND FREE DESIGN FOR YOUR CLUB :::</a></font></b></font></p></td> </tr> </table> </td> </tr> </table> </TD> </TR> </TBODY> </TABLE> </body> </html> <?PHP } mysql_close($link); ?> for reference here are the pages that should work, the second page below for listing the section contents does work... http://www.club-noticeboard.co.uk/stowmarket/results.php http://www.club-noticeboard.co.uk/stowmarket/results.php?S=March+2007 Quote Link to comment https://forums.phpfreaks.com/topic/86143-help-with-php-script-that-used-to-work/ Share on other sites More sharing options...
kenrbnsn Posted January 15, 2008 Share Posted January 15, 2008 It looks like the old server had register_globals enabled and the new server does not, which is the correct setting. Since the script is getting the variable $S from the URL, you need get the value from the super global array $_GET. Instead of: <?php if($S!=""){ echo " - "; echo $S; }?> use <?php if($_GET['S'] != ''){ echo ' - ' . $_GET['S']; }?> Do the same for other variables that expect values from the URL. Ken Quote Link to comment https://forums.phpfreaks.com/topic/86143-help-with-php-script-that-used-to-work/#findComment-439947 Share on other sites More sharing options...
terryhawkins Posted January 15, 2008 Author Share Posted January 15, 2008 This part of the script does actually work, it's picking up what's passed through the URL no problem. The problem is with displaying the table, I'm not sure if it's not making the array correctly or if the foreach loop isn't working. Thanks Terry Quote Link to comment https://forums.phpfreaks.com/topic/86143-help-with-php-script-that-used-to-work/#findComment-439957 Share on other sites More sharing options...
terryhawkins Posted January 15, 2008 Author Share Posted January 15, 2008 I think one of these is the problem, but I don't know which: $sections = array(); $sql = "SELECT section FROM stowmarket WHERE display = 'yes' ORDER BY news_date"; $results=mysql_query($sql, $link); while($result = mysql_fetch_array($results,$link)){ array_push($sections,trim($result['section'])); } $sections = array_unique($sections); $counter = 0; or <table width="100%" border="0" cellpadding="4" cellspacing="1"> <tr> <?PHP foreach($sections as $section){ $counter++; ?> <td width="25%" class="ResBox"><a class="MainTextFont" href="<?PHP echo $PHP_SELF."?S=".urlencode($section); ?>"> <?PHP echo $section; ?></a></td> <?PHP if($counter/$numOfColumnsSec == intval($counter/$numOfColumnsSec)){ ?> </tr> <tr> <?PHP } } ?> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/86143-help-with-php-script-that-used-to-work/#findComment-439961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.