?
Solved

Php and mysql

Posted on 2001-06-06
6
Medium Priority
?
338 Views
Last Modified: 2006-11-17
I have a mysql database that lists 5 thousand businesses and i have wrote a php page that will pull back the first 5 listings and tell the person how many are relative to there seach.

So all businesses in essex will show the first 5 and say there are a total of 88.

how do i make it so that it will say there are x ammount of pages so that the user can click on the page number or next or prvious

like Altavista

0
Comment
Question by:Boroughman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:higijj
ID: 6161514
Well.. you do one queries to get the total number of business

and divide it by 5 to get the number of pages.

0
 

Accepted Solution

by:
hongs earned 150 total points
ID: 6162375
The total records:$totalcount=mysql_num_rows($result);
The total pages:$totalpages=ceil($totalcount/5);
0
 

Expert Comment

by:hongs
ID: 6162491
<?
//A simple sample

$hostname="localhost";
$username="root";
$password="";
$dbname="db1";
mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
$query="select field1,fields from table1";
$result=mysql_query($query);

$intCount=mysql_num_rows($result);     //Total records
$intEach=5;                    //Records each page
$intPages=ceil($intCount/$intEach);     //Total Pages
if(!$intPage)
     $intPage=1;               //page No
     

mysql_data_seek($result,($intPage-1)*$intEach);
for($i=0;$i<5;$i++)
{
     if($row=mysql_fetch_row($result))
     print $row[0]."-".$row[1]."<BR>\n";
}

print "<HR>";
if($intPage>1)
     print "<a href=\"".basename($PHP_SELF)."?intPage=".($intPage-1)."\">Prev Page</a>|";
else
     print "Prev Page|";
if($intPage<$intPages)
     print "<a href=\"".basename($PHP_SELF)."?intPage=".($intPage+1)."\">Next Page</a>|";
else
     print "Next Page|";
print $intPage." of ".$intPages;
?>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Boroughman
ID: 6162859
could you do it so that it look like this



Results Pages: 1|2|3|4|5|6|7|8|9|10 [Next >>]
0
 

Expert Comment

by:hongs
ID: 6166267
<?
//A simple sample.
//Results Pages: 1|2|3|4|5|6|7|8|9|10 [Next >>]

$hostname="localhost";
$username="root";
$password="";
$dbname="db1";
mysql_connect($hostname,$username,$password);
mysql_select_db($dbname);
$query="select field1,field2 from step";
$result=mysql_query($query);

$intCount=mysql_num_rows($result);     //Total records
$intEach=5;                    //Records each page
$intPages=ceil($intCount/$intEach);     //Total Pages
if(!$intPage) $intPage=1;          //page No
     
$intEachFrame=10;               //Pages each frame
$intFrame=ceil($intPage/$intEachFrame);     //Frame No.
$intFrames=ceil($intPages/$intEachFrame);//Total Frames

mysql_data_seek($result,($intPage-1)*$intEach);
for($i=0;$i<$intEach;$i++)
{
     if($row=mysql_fetch_row($result))
     print $row[0]."-".$row[1]."<BR>\n";
}

print "<HR>";
if($intFrame>1)
     print "<a href=\"".basename($PHP_SELF)."?intPage=".($intFrame-1)*$intEachFrame."\">[<< Prev]</a>|";

$temp1=($intFrame-1)*$intEachFrame;
for($j=1;$j<=$intEachFrame;$j++)
{
     $temp=$temp1+$j;
     if($temp<=$intPages)
     {
          if($temp==$intPage)
               print "<a href=\"".basename($PHP_SELF)."?intPage=".$temp."\"><label style='color:red'>".$temp."</label></a>";
          else
               print "<a href=\"".basename($PHP_SELF)."?intPage=".$temp."\">".$temp."</a>";
     }
     else
     {
          print $temp;
     }
     if($j==$intEachFrame)
          print " ";
     else
          print "|";
}    

if($intFrame<$intFrames)
     print "<a href=\"".basename($PHP_SELF)."?intPage=".($intFrame*$intEachFrame+1)."\">[Next >>]</a>";
else
     print "[Next >>]";


?>
0
 

Author Comment

by:Boroughman
ID: 6199483
im now using your first answer with the next and back button but if the result is 0 i get an error
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question