Solved

Php and mysql

Posted on 2001-06-06
6
321 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

20 Experts available now in Live!

Get 1:1 Help Now