Haven't slept in 2 days now someone plz help with this search code basically it won't search the database unless the vars are sent by $_POST . even then it won't let me switch between pages so it sends the vars through post and when a page number is selected this is supposed to show that page. This project is for a favour to a guy i know and i wanna get it to hm by some point tomorrow.
<?php
$searchdata = file_get_contents("./search/search.dat");
$Results = 0;
//Do Search Now
$searchterms = $_GET['s'];
if (($searchterms != "") && ($searchterms != " ")){
// Okay they have typed something
if (strstr($searchterms, "_")){
$searchtermz = explode ("%20", $searchterms);
}
if (!strstr($searchterms, "_")){
$searchtermz = $searchterms;
}
foreach ($searchtermz as $searchterm){
$entries = explode("\r\n", $searchdata);
foreach ($entries as $entry){
$getinfo = explode("|", $entry);
if (preg_match("/^(.*)" . strtolower($searchterm) . "(.*)/i",strtolower($getinfo[2]))){
// These are positive results
$Resultslist .= "\r\n\t<tr>\r\n\t\t<td width=\"100\">\r\n\t\t<img src=\"".$getinfo[1].
"\">\r\n\t\t</td>\r\n\t\t<td width=\"300\">\r\n\t\t<b>".$getinfo[2]."</b><br>\r\n\t\t".
"<a href=\"".$getinfo[3]."\">".$getinfo[3]."</a><br>\r\n".
"<a href=\"".$getinfo[4]."\">".$getinfo[8]."</a><br>\r\n".
$getinfo[9]."<br>\r\n".
$getinfo[5]."<br><br>\r\n\t\t</td>\r\n\t</tr>\r\n\t<sep>";
$Results ++;
}
if (preg_match("/^(.*)" . strtolower($searchterm) . "(.*)/i",strtolower($getinfo[5]))){
// These are positive results
$Resultslist .= "\r\n\t<tr>\r\n\t\t<td width=\"100\">\r\n\t\t<img src=\"".$getinfo[1].
"\">\r\n\t\t</td>\r\n\t\t<td width=\"300\">\r\n\t\t<b>".$getinfo[2]."</b><br>\r\n\t\t".
"<a href=\"".$getinfo[3]."\">".$getinfo[3]."</a><br>\r\n".
"<a href=\"".$getinfo[4]."\">".$getinfo[8]."</a><br>\r\n".
$getinfo[9]."<br>\r\n".
$getinfo[5]."<br><br>\r\n\t\t</td>\r\n\t</tr>\r\n\t<sep>";
$Results ++;
}
}
}
$getallresults = explode("<sep>", $Resultslist);
$getresultscount = count($getallresults)-1;
$pagestocount = (int) ($getresultscount / 10);
$schtrms = $_GET['s'];
echo "<center><table>";
if ($getresultscount < 10){
// we will have to paginate the page
echo "<a href=?page=search&s=".$schtrms."&pg=start><< start</a> ";
echo "<a href=?page=search&s=".$schtrms."&pg=end>end >></a>";
$pg = ($_GET['pg']);
$startfig = ($pg * 10);
$endfig = ("+10");
$pgnumbase = (array_slice($getallresults, $startfig, $endfig));
$pgnum = implode('',$pgnumbase);
echo $pgnum;
}
elseif (!isset($_GET['pg'])){
$pg1base = (array_slice($getallresults, 0, 9));
$pg1 = implode('',$pg1base);
foreach (range(1, $pagestocount) as $number) {
echo "<a href=?page=search&s=".$schtrms."&pg=" . $number . ">" . $number . " </a>";
}
echo "<a href=?page=search&s=".$schtrms."&pg=end>end >></a>";
echo $pg1;
}
elseif ($_GET['pg']=="all") {
echo $Resultslist;
}
elseif ($_GET['pg']=="end") {
echo "<a href=?page=search&s=".$schtrms."&pg=start><< start</a> ";
foreach (range(1, $pagestocount) as $number) {
echo "<a href=?page=search&s=".$schtrms."&pg=" . $number . ">" . $number . " </a>";
}
$pg1base = (array_slice($getallresults, ($getresultscount - 10), $getresultscount));
$pg1 = implode('',$pg1base);
echo $pg1;
}
elseif ($_GET['pg']=="start") {
foreach (range(1, $pagestocount) as $number) {
echo "<a href=?page=search&=".$schtrms."&pg=" . $number . ">" . $number . " </a>";
}
echo "<a href=?page=search&s=".$schtrms."&pg=end>end >></a>";
$pg1base = (array_slice($getallresults, 0, 9));
$pg1 = implode('',$pg1base);
echo $pg1;
}
elseif (isset($_GET['pg'])){
echo "<a href=?page=search&s=".$schtrms."&pg=start><< start</a> ";
foreach (range(1, $pagestocount) as $number) {
echo "<a href=?page=search&s=".$schtrms."&pg=" . $number . ">" . $number . " </a>";
}
echo "<a href=?page=search&s=".$schtrms."&pg=end>end >></a>";
$pg = ($_GET['pg']);
$startfig = ($pg * 10);
$endfig = ("+10");
$pgnumbase = (array_slice($getallresults, $startfig, $endfig));
$pgnum = implode('',$pgnumbase);
echo $pgnum;
}
echo "</table></center>";
}
?>
thanx again it seems like you guys are saving my back all the time now