PDA

View Full Version : Can't link to next page...


Alex Piotto
08-28-2002, 10:39 AM
Hi people!

I can't have the link to netx page to works.... the code below split the results of a search ($results), and in the first page shows 10 items... and so far is good.
But the links to next (or previous) pages doesn't works...

code:
______________________

// Write down paged search results
$s=sizeof($results);
$items_per_page = 10;
if ($linkpage=='' or !$linkpage) { $linkpage=1; }
$end=$items_per_page*$linkpage;
$start=$end-$items_per_page;

if ($start<>'0') { $new_page=$linkpage-1;
$prev="<a href='searchTEST.php?linkpage=$new_page'>Previous page</a>";} else {$prev="";}

if ($end<$s) { $new_page1=$linkpage+1;
$next="<a href='searchTEST.php?linkpage=$new_page1'>Next page</a>";} else {$next="";}

for ($i=$start; $i<$end; $i++) {
echo "<b>ID: </b>" . $results[$i][0] . "<br />";
echo "<b>Bairro: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][1]) . "<br />";
echo "<b>Genero: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][2]) . "<br />";
echo "<b>Tipo: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][3]) . "<br />";
echo "<b>USD/Mês: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][4]) . "<br />";
echo "<b>Descrição: </b>" . preg_replace($searchPattern, "<span style='color:red;'>\\1</span>", $results[$i][5]) . "<br /><hr>\n";
}
}
echo "</div>";

// Write down next and prev links and the total numers of pages with links
echo "<table style='font-family:verdana; font-size:13px;' width='100%'><tr><td width='50%' align='left'><b>$prev&nbsp;&nbsp;$next</b></td>";

$pages=$s/$items_per_page;
$pages1=round($pages, 2);
$p=explode('.', $pages1);
$pcount=count($p);
$ext=$p[$pcount-1];
if ($ext!=0) {$num=$p[0]+1;}
else {$num=$p[0];}
echo "<td width='50%' align='right'>Páginas: ";
for ($i=1; $i<=$num; $i++) {if ($i==$page) {echo "<B>$i</B> ";}
else {echo "<a href='searchTEST.php?linkpage=$i'>[$i]</a> ";}

}
}
echo "</td></tr></table>";
____________________________

Please, a little help... I am getting crazy on this! :( :confused:

Thanks

Alex

mordred
08-28-2002, 10:55 AM
Be more specific. What exactly does not work - can't you get the links to be printed or are they broken in their URL or when you click them and come to the next page, but without the paging results?

Alex Piotto
08-28-2002, 11:05 AM
Hi mordred...
if I click on the links at the bottom of the page I dont get any result... just a blank page.

note: $results come from your script

Alex

mordred
08-28-2002, 11:06 AM
After removing some superfluous curly braces from your code excerpt, everything seemed to work ok for me it seems... I just commented out the last loop and the "next page" and "previous page" were printed correctly... :confused:

Maybe you have a problem with persistent storage of your search results?

Alex Piotto
08-28-2002, 11:19 AM
Actually, this may be the problem... but how to solve it?
If I click the links I get a blank page, signal that the results are not there anymore...

Alex

mordred
08-28-2002, 11:56 AM
Store the results array as a session variable, if you can use sessions. If not... maybe write it to a temporary file and pass this filename as a parameter to the next page?

Alex Piotto
08-28-2002, 11:59 AM
Thanks mordred. I'll try it

ciao

Alex