Click to See Complete Forum and Search --> : pages results
sandro27
11-23-2004, 06:41 PM
Hello world !!
I am trying to get the variables across to get the nest page results, but i donīt know how to do it.
include "intro.php";
$area=$_POST['area'];
$category=$_POST['acc_category'];
$beach_dist=$_POST['beach_dist'];
$conv_dist=$_POST['conv_dist'];
$sql="select * from accommodation,area,acc_category where
area.area_id=accommodation.area and accommodation.category_id=acc_category.acc_category_id
and area='$area'
and acc_category_id='$category'
and beach_dist_id='$beach_dist'
and conv_dist_id='$conv_dist' order by acc_name limit $from,$max_results";
$busca=mysql_query($sql,$conexao) or die(mysql_error());
$lista=mysql_fetch_array($busca);
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM accommodation,area,acc_category where
area.area_id=accommodation.area
and accommodation.category_id=acc_category.acc_category_id
and area='$area'
and acc_category_id='$category'
and beach_dist_id='$beach_dist'
and conv_dist_id='$conv_dist'"),0);
$total_pages = ceil($total_results / $max_results);
echo "<strong><font color='#003366' size='2'>Pages: </font></strong>";
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><strong><font size='2'>Previous</font></strong></a> ";
}
for($i=1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "<font color='#FF6633' size='2'><strong>$i </font></strong>";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&area=$area&acc_category_id=$category&beach_dist_id=$beach_dist&conv_dist_id=$conv_dist\"><strong><font size='2'>$i</font></strong></a> ";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"><strong><font size='2'>Next>></font></strong></a>";
}
echo "</center>";
How is it possible?
Thanks for any help.
ShrineDesigns
11-23-2004, 10:26 PM
not too sure what your asking for.
if you're using mysql 4.0 or greater, SQL_CALC_FOUND_ROWS and FOUND_ROWS() are a quick way of finding out the maximum rows without resending the same query without the LIMIT set, try something like this:<?php
$link = mysql_pconnect('localhost', 'user', 'password');
mysql_select_db('database', $link);
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM `table` LIMIT " . ($page_number - 1) * $per_page . "," . $per_page;
$primary_result = mysql_query($sql, $link);
$secondary_result = mysql_query("SELECT FOUND_ROWS()", $link);
$total_rows = mysql_result($secondary_result, 0);
while($row = mysql_fetch_array($primary_result, MYSQL_NUM))
{
// ...
}
mysql_free_result($primary_result);
// ...
?>
sandro27
11-24-2004, 07:03 AM
Hi Shrine.
Thak you for the script. However IO am bit confused about it or maybe I didn't make myself clear.
I need the variables bellow to go across the next results page
$area=$_POST['area'];
$category=$_POST['acc_category'];
$beach_dist=$_POST['beach_dist'];
$conv_dist=$_POST['conv_dist'];
I need this because it seems that on the next page results it doesn't not show me anyhting.
I have tried the script bellow but it is not working:
for($i=1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "<font color='#FF6633' size='2'><strong>$i </font></strong>";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i&area=$area&acc_category_id=$category&beach_dist_id=$beach_dist&conv_dist_id=$conv_dist\"><strong><font size='2'>$i</font></strong></a> ";
}
}
Hope you can help me. I really stck on this one.
scragar
11-24-2004, 07:18 AM
use $_GET['term'] not $_POST['term'] when getting values for the querystring.
sandro27
11-24-2004, 07:32 AM
Hi,
The values for the variables come from a form. Does it work using GET ?
I have tried using both in the same script like:
$area=$_POST['area'];
$category=$_POST['acc_category'];
$beach_dist=$_POST['beach_dist'];
$conv_dist=$_POST['conv_dist'];
$area=$GET['area'];
$category=$GET['acc_category'];
$beach_dist=$GET['beach_dist'];
$conv_dist=$GET['conv_dist'];
$sql="select * from accommodation,area,acc_category where
area.area_id=accommodation.area and accommodation.category_id=acc_category.acc_category_id
and area='$area'
and acc_category_id='$category'
and beach_dist_id='$beach_dist'
and conv_dist_id='$conv_dist' order by acc_name limit $from,$max_results";
It is not working this way, though.
scragar
11-24-2004, 08:17 AM
try:
<?
$area=$POST['area'];
if($area != ""){
$area=$GET['area'];
};
$category=$_POST['acc_category'];
if($category != ""){
$category=$GET['acc_category'];
};
$beach_dist=$_POST['beach_dist'];
if($beach_dist != ""){
$beach_dist=$GET['beach_dist'];
};
$conv_dist=$_POST['conv_dist'];
if($conv_dist != ""){
$conv_dist=$GET['conv_dist'];
};
$sql="select * from accommodation,area,acc_category where
area.area_id=accommodation.area and accommodation.category_id=acc_category.acc_category_id
and area='$area'
and acc_category_id='$category'
and beach_dist_id='$beach_dist'
and conv_dist_id='$conv_dist' order by acc_name limit $from,$max_results";
?>
This should do a quick check to see if it has been submited in a form, and if not retrive it from the querystring.
The way you are doing it is overwriting it's retrival from the form when you get it from the querystring.
sandro27
11-24-2004, 08:19 AM
Hummm looks good.
I will try it and let you know
Many Thanks
Sandro27
sandro27
11-25-2004, 07:29 AM
Humm the script didnīt work.
I quite didnīt undesrtand this
if($conv_dist != ""){
$conv_dist=$_GET['conv_dist'];
};
Cheers
scragar
11-25-2004, 07:43 AM
OOPS.
replace != with == I acidentaly got the two mixed up because I never though enought about what I was writing.
<?
$area=$POST['area'];
if($area == ""){
$area=$GET['area'];
};
$category=$_POST['acc_category'];
if($category == ""){
$category=$GET['acc_category'];
};
$beach_dist=$_POST['beach_dist'];
if($beach_dist == ""){
$beach_dist=$GET['beach_dist'];
};
$conv_dist=$_POST['conv_dist'];
if($conv_dist == ""){
$conv_dist=$GET['conv_dist'];
};
$sql="select * from accommodation,area,acc_category where
area.area_id=accommodation.area and accommodation.category_id=acc_category.acc_category_id
and area='$area'
and acc_category_id='$category'
and beach_dist_id='$beach_dist'
and conv_dist_id='$conv_dist' order by acc_name limit $from,$max_results";
?>
This should now work (or at least did in test...)
sandro27
11-25-2004, 08:21 AM
Hi Scragar,
Thanks for that.
Unfortunately the script is not working. For some reason when I go to the next page results (number 2, letīs say), it come out as empty.
I am not sure whether the problem is in the variables but I guess it might be because I have done this type of page numbering once without using variable to determine the values on the SQL string and it worked.
I just donīt know why this one is not working
$sql="select * from accommodation,area,acc_category where
area.area_id=accommodation.area and accommodation.category_id=acc_category.acc_category_id
and area='$area'
and acc_category_id='$category'
and beach_dist_id='$beach_dist'
and conv_dist_id='$conv_dist' order by acc_name limit $from,$max_results";
$busca=mysql_query($sql,$conexao) or die(mysql_error());
$lista=mysql_fetch_array($busca);
Paul Jr
11-25-2004, 09:19 AM
On the first page access them via $_POST, since they are being submitted from a form via HTTP POST. On the second page access them via $_GET, since you are passing them through the querystring.
sandro27
11-25-2004, 09:44 AM
Ok. I am trying to do this but the problem is that I get the second page with this script:
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
$max_results = 2;
$from = (($page * $max_results) - $max_results);
I just donīt how to get the next page results to _GET the variables.