Solved

Php and mysql

Posted on 2001-06-06
6
325 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now