I'm writing a script take takes some postdata from a search form, builds an array via a SQL query, and then paginates the results. The problem I'm experiencing right now stems from the array of results-- it disappears when the page is changed. I've been banging my head against this problem for a while now and I can't seem to figure it out.
I've uploaded the code here: http://snipt.org/knli, but here are the relevant snippets....
Code: Select all
$page=$_GET['page'];
$selectedgenre = $_POST['selectedgenre'];
$selecteddate = $_POST['selecteddate'];
$selectedvenue = $_POST['selectedvenue'];
if (($selectedgenre) || ($selecteddate) || ($selectedvenue))
{
$page=1;
}
$numperpage=2;
function showResults($page,$results,$numperpage) {
if($page==1) {
$offset=0;
} else {
$offset=($page-1)*$numperpage+1;
}
$BandstoDisplay=array_slice($results,$offset,$numperpage);
//print_r($BandstoDisplay);
echo "<br><br><br>offset is " . $offset ."<br><br><br>";
foreach($BandstoDisplay as $Band)
{
$Band=trim($Band);
$SQL= "SELECT SHOWS.Date, SHOWS.Band, SHOWS.Venue, SHOWS.Allbands, BANDS.EmbedCode, SHOWS.Genre FROM SHOWS, BANDS WHERE BANDS.Band='$Band' AND SHOWS.Band='$Band'";
//echo $SQL;
$result=mysql_query($SQL) or die('A error occured: ' . mysql_error());
while($row=mysql_fetch_assoc($result)) {
$code=$row['EmbedCode'];
$allbands=$row['Allbands'];
$venue=$row['Venue'];
$date=$row['Date'];
echo "<font size =4><i>" . $allbands ." <font size=6>::<font size=4> " . $venue . "<font size=6> :: <font size=4>" . $date . "<br>";
echo $code . "<br><br>";
}
}
}
Code: Select all
//build query
if (($selectedgenre) || ($selecteddate) || ($selectedvenue)) {
$i = 0;
foreach ($_POST['selectedgenre'] as $a => $b) {
if ($i == 0) {
$query .= "SELECT Band from SHOWS WHERE Genre LIKE '%$b%'";
$i++;
} else {
$query .= " || Genre LIKE '%$b%'";
}
}
echo "postdata still active on page " . $page;
if($selecteddate) {
$query.=" AND Date='$selecteddate'";
}
if($selectedvenue) {
$query.=" AND Venue='$selectedvenue'";
}
$Bands=array();
$theresult = mysql_query($query) or die('A error occured: ' . mysql_error());
while ($row = mysql_fetch_assoc($theresult)) {
$Band=trim($row['Band']);
array_push($Bands,$Band);
}
//print_r($Bands);
echo "<br><br>";
}
echo "page is " . $page . "<br><bR><br>";
showResults($page,$Bands,$numperpage);
showSearchForm();
print_r($Bands);
if($page>1) {
echo '</i><div id="backbutton" style="position:fixed; bottom:5px; left:5px;"><font size=6><a href="'.$_SERVER['PHP_SELF'].'?page='.($page-1).'"></i>.: Back';
}
echo '</i><div id="nextbutton" style="position:fixed; bottom:5px; right:5px;"><font size=6><a href="'.$_SERVER['PHP_SELF'].'?page='.($page+1).'"> Next :.';
The postdata comes from an index page and is submitted to search.php (which is where the code above comes from). How do I pass the results array to the next page??? I'm sure this code looks like spaghetti to all you leet PHPers out there, but any help you can provide would be much appreciated!!
Thanks!
Nick
'