Solved

Php and mysql

Posted on 2001-06-06
6
331 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
  • 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 50 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ajax and PHP 9 53
Special characters in a TCPDF 4 23
PHP $_POST vs asp request 4 19
Dump data from mysql to xls php 10 14
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

679 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