Hi all,
I have a MySQL database full with authors and titles. I made a script that
searchs a specific author and return the all his books titles, but I need it
show the results from 10 to 10. I tried with LIMIT and it return just fine
the first 10 but when I click the next 10 button it show me other 10
registers but from all the database not from the author selection I choosed.
So I think it only reads the variable I send from the form once, the second
time it seems not to read the author I want to find. The code is this:
<?php
$buscar = $HTTP_GET_VARS['buscar'];
$conex = @mysql_connect("localhost", "root", "");
@mysql_select_db("boc", $conex);
if (!isset($_GET['page'])){
$page = 1;
}else{
$page = $_GET['page'];
}
$num_result = 8;
$from = (($page * $num_result) - $num_result);
$sql = "SELECT * FROM boletines WHERE (author LIKE '%$buscar%') LIMIT $from,
$num_result";
$res = mysql_query($sql, $conex);
if (!isset($tot)){
$totquery = "SELECT * FROM boletines WHERE (author LIKE '%$buscar%')";
$tot = mysql_query($totquery, $conex);
}
$total_results = mysql_num_rows($tot);
if (mysql_num_rows($res)==0){
echo "0 RESULTS";
}else{
echo $total_results." RESULTS FOUNDED";
echo "<TABLE>";
echo "<TR><TD>AUTHOR</TD>";
echo "<TD>TITLE</TD>";
echo "<TD>PAGES</TD>";
echo "<TD>VOL</TD></TR>";
while ($row = mysql_fetch_array($res)){
echo "<TR><TD>".$row["Author"]."</TD>";
echo "<TD>".$row['Title']."</TD>";
echo "<TD>".$row['pages']."</TD>";
echo "<TD>".$row['Vol']."</TR>";
}
echo "</TABLE>";
}
//previous link
$total_pages = ceil($total_results / $max_results);
if ($page > 1){
$prev = ($page - 1);
echo "<a
href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a
href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// next link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
?>
I would appreciate any help.
I'm a newby, so be the most especific you can...Many thanks guys.
Andres
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php