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 $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
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 $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