Solved

Php and mysql

Posted on 2001-06-06
6
336 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
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 …

734 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