PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old August 18th, 2002, 05:43 PM
winey winey is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Pasadena, CA usa
Posts: 4 winey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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> | ";
}

Reply With Quote
  #2  
Old August 18th, 2002, 07:51 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to bakertrg
RE: problems with limiting records/paging results

Your LIMIT is added to the SQL statement after you have already called your results.

B

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > problems with limiting records/paging results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT