PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Everah | Please use the appropriate bbCode tags when posting code in the forums.
Hey there,
I have a search page on my clients site, which searches through mysql database and sends back info with limit of 10 results function. This function works fine on another server with php4 but when i use it on a server with php5, and you click on the "next 10 results link" it just shoots back the same 10 results as before. i am pretty sure this is a syntax issue regarding the differences between php 4 and 5, (but not sure).
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$PHP_SELF?s=$prevs&q1=$var1&q2=$var2\" class = \"normlinks\"><<
Prev 10</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href=\"$PHP_SELF?s=$news&q1=$var1&q2=$var2\" class = \"normlinks\">Next 10 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
echo "<br><a href=\"search.html\" class = \"normlinks\">Back to Search</a>";
echo "</td></tr></table>";
I am sure the error is this part of the code... any help would be much appreciated thanks you.
Hey mate, thanks yeah you were right. I inserted error reporting and got this:
Notice: Undefined variable: $PHP_SELF in D:\Inetpub\aih\directory\searchscript.php on line 163
Do i replace $PHP_SELF with $_SERVER['PHP_SELF'] can you give me the correct code to replace this line:
echo " <a href=\"$PHP_SELF?s=$news&q1=$var1&q2=$var2\" class = \"normlinks\">Next 10 >></a>";
Because when i do i get a blank page.
(sorry quite new to php).
I have register globals turned off on the new server, although i find that i run into problems when passing variables between flash and php if _globals is off, do you experience this.
Thanks i tried both these suggestions, i get rid of the error message but the script still doesn't bring up the next ten pages, seems to be not passing the s variable and the $prevs variable in the query string, mabye???, or not being able to be read by the page. Should i paste the whole code???
richoes:
Register globals affects all variables!. So best you do is modify your code.. .$s = $_GET['s']; etc... with proper validation and all. but error_reporting should have mentioned these variable are undefined.