|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
problems with limiting records/paging results
I've put together a search section for my wine web directory site, but I'm having a problem with breaking it into pages and numbering. the numbering is appearing at the bottom of the results list, but all the results are being returned on the first page, even though there should only be 15.
Site can be found at: http://www.winereader.com/search.php here's the code I'm using: // database connection stuff here include ('dbconnect.inc'); mysql_select_db("winereaderdb",$dbcnx); $searchstring = explode(", ",$keywords); sort($searchstring); $l = count($searchstring); $rows_per_page = 15; for ($i = 0; $i < $l ; $i++) { $sql = "SELECT * FROM sites where description like '%$searchstring[$i]%' or name like '%$searchstring[$i]%' ORDER BY name ASC "; $result = mysql_query($sql,$dbcnx) or die("Couldn't execute query."); } $total_records = mysql_num_rows($result); $pages = ceil($total_records / $rows_per_page); mysql_free_result($result); if (!isset($screen)) $screen = 0; $start = $screen * $rows_per_page; for ($i = 0; $i < $l ; $i++) { $sql = "SELECT * FROM sites where description like '%$searchstring[$i]%' or name like '%$searchstring[$i]%' ORDER BY name ASC "; $result = mysql_query($sql,$dbcnx) or die("Couldn't execute query."); $sql .= "LIMIT $start, $rows_per_page"; $rows = mysql_num_rows($result); while ( $row = mysql_fetch_array($result) ) { $id = $row["id"]; $name = $row["name"]; $url = $row["url"]; $description = $row["description"]; echo ("<p><a href='$url' target='_blank'>$name</a><br> $description</p>"); } } $youhere=$screen+1; echo "<hr> You are on page $youhere of $pages.<br>"; // page numbering links now for ($i = 0; $i < $pages; $i++) { $url = "searchresults.php?screen=" . $i; $pagenumber=$i+1; echo " | <a href="$url">$pagenumber</a> | "; } |
|
#2
|
||||
|
||||
|
RE: problems with limiting records/paging results
Your LIMIT is added to the SQL statement after you have already called your results.
B |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > problems with limiting records/paging results |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|