Problemi con paginazione dei risultati

bluabarth

Nuovo Utente
21 Lug 2009
1
0
0
Buongiorno a tutti,

Sono nuovo del forum e ho deciso di postare qui il mio problema con la speranza che qualcuno possa aiutarmi.
Premetto che ho delle conoscenze di PHP elementari e che sto cercando di modificare una query già esistente.

Il problema è questo: il codice che riporto di seguito effettua una query raccogliendo dati presenti su due tabelle diverse e restituisce i risultati relativi. Effettua anche la paginazione (15 per pagina) ma il problema è che quando si passa a visualizzare le pagine successive, invece che mostrare i risultati a partire dal 16°, vengono riportati sempre i primi 15 risultati.

Il codice è questo (riporto tutta la pagina):

<?
require_once("conn.php");
require_once("includes.php");
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
$max_results = 15;
$from = (($page * $max_results) - $max_results);
$query = array();

if(!empty($_GET[c]))
{
$query[] = "cars_listings.CategoryID = '$_GET[c]' ";
}

if(!empty($_GET[AgentID]))
{
$query[] = "cars_listings.AgentID = '$_GET[AgentID]' ";
}

if(!empty($_GET[search_country]))
{
$query[] = "cars_agents.country = '$_GET[search_country]' ";
}

if(!empty($_GET[search_state]))
{
$query[] = "cars_agents.state = '$_GET[search_state]' ";
}

if(!empty($_GET[search_city]))
{
$query[] = "cars_agents.city = '$_GET[search_city]' ";
}

if(!empty($_GET[min]))
{
$query[] = "cars_listings.price >= '$_GET[min]' ";
}

if(!empty($_GET[max]))
{
$query[] = "cars_listings.price <= '$_GET[max]' ";
}

if(!empty($_GET[year1]))
{
$query[] = "cars_listings.VehicleYear >= '$_GET[year1]' ";
}

if(!empty($_GET[year2]))
{
$query[] = "cars_listings.VehicleYear <= '$_GET[year2]' ";
}

if(!empty($_GET[before]))
{
$MyDate = strtotime("-$_GET[before]");
$query[] = "cars_listings.DateAdded >= '$MyDate' ";
}

if(!empty($_GET[SelectMake]))
{
$query[] = "cars_listings.vehiclemake = '$_GET[SelectMake]' ";
}

if(!empty($query))
{
$MyQuery = implode(" and ", $query);
$MyQuery = " and ".$MyQuery;
}


////////////////////////////////////////////////////////////
////////// order by
////////////////////////////////////////////////////////////







$q1 = "select * from cars_listings, cars_agents, cars_priority, cars_vehicle where cars_listings.AgentID = cars_agents.AgentID and cars_agents.PriorityLevel = cars_priority.PriorityLevel and cars_agents.AccountStatus = 'active' and cars_listings.VehicleMake = cars_vehicle.VehicleID $MyQuery order by cars_agents.PriorityLevel desc, cars_listings.DateAdded asc limit $from, $max_results ";
$total_results = mysql_num_rows(mysql_query("select * from cars_listings, cars_agents, cars_priority, cars_vehicle where cars_listings.AgentID = cars_agents.AgentID and cars_agents.PriorityLevel = cars_priority.PriorityLevel and cars_agents.AccountStatus = 'active' and cars_listings.VehicleMake = cars_vehicle.VehicleID $MyQuery"));

$total_pages = ceil($total_results / $max_results);

$qnav = "select * from cars_listings, cars_agents where cars_listings.AgentID = cars_agents.AgentID $MyQuery";

$r1 = mysql_query($q1) or die(mysql_error());
$lrows = mysql_num_rows($r1);

if($lrows > '0')
{
$ListingTable .= "<table align=center width=95% cellspacing=0>\n";
$ListingTable .= "<tr>\n<td width=75>&nbsp;</td>\n\t";

$ListingTable .= "<td width=200 align=center><a class=BlackLink href=\"search.php?c=$_GET[c]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&min=$_GET[min]&max=$_GET[max]&year1=$_GET[year1]&year2=$_GET[year2]&before=$_GET[before]&vehicle=$_GET[vehicle]\">Vettura</a></td>\n\t";

$ListingTable .= "<td width=125 align=center><a class=BlackLink href=\"search.php?c=$_GET[c]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&min=$_GET[min]&max=$_GET[max]&year1=$_GET[year1]&year2=$_GET[year2]&before=$_GET[before]\">Chilometraggio</a></td>\n\t";

$ListingTable .= "<td align=center width=100><a class=BlackLink href=\"search.php?c=$_GET[c]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&min=$_GET[min]&max=$_GET[max]&year1=$_GET[year1]&year2=$_GET[year2]&before=$_GET[before]\">Prezzo</a></td>\n";

$ListingTable .= "</tr>\n</table>\n\n";

$ListingTable .= "<table align=center width=95% border=1 bordercolor=#999999 rules=rows cellspacing=0>\n";

while($a1 = mysql_fetch_array($r1))
{
$ListingTable .= "<tr style=\"border-width:1; border-color:grey\" onMouseOver=\"this.style.background='#CCD1C4'; this.style.cursor='hand'\" onMouseOut=\"this.style.background='white'\" onClick=\"window.open('info.php?id=$a1[ListingID]', '_top')\">\n\t";
$ListingTable .= "<td height=60>";

$ListingTable .= "<table align=center width=\"100%\">\n";

$ListingTable .= "<caption align=center>";
if($aset[Sitefee]=="0")
{
if($a1[PriorityLevel] > '1')
{
$ListingTable .= "<span class=RedLink>$a1[PriorityName] listing</span></caption>\n";
}
}
$ListingTable .= "<tr>\n\t<td width=75>";

if(!empty($a1[image]))
{
$images = explode("|", $a1[image]);
$MyImage = $images[0];

$ListingTable .= "<img src=\"cars_images/$MyImage\" width=80 height=60 border=1>";
}
else
{
$ListingTable .= "<img src=\"no_image.gif\" border=1>";
}

$ListingTable .= "</td>\n\t";

$MyMiles = number_format($a1[mileage], 0, "", "'");

$ListingTable .= "<td width=225 valign=top><b>$a1[VehicleName] $a1[VehicleModel]</b><br>Offer ID: $a1[ListingID]</td>\n\t";
$ListingTable .= "<td width=100 valign=top align=center>$MyMiles miles<br>$a1[VehicleYear] year</td>\n\t";

$MyPrice = number_format($a1[Price], 2, ".", "'");

$ListingTable .= "<td align=center width=100 valign=top><b>$aset[Currencya]$MyPrice</td>\n";

$ListingTable .= "</tr>\n";

$ShortDesc = substr($a1[DetailedDesc], 0, 200);

$ListingTable .= "<tr>\n\t<td colspan=4>$ShortDesc</td>\n</tr>\n";

$ListingTable .= "</table>\n\n</td>\n</tr>\n\n";

}

$ListingTable .= "</table>";

$rnav = mysql_query($qnav) or die(mysql_error());
$rows = mysql_num_rows($rnav);

if($rows > $max_results)
{
$ListingTable .= "<br><table align=center width=580>";
$ListingTable .= "<td align=center><font face=verdana size=2> | ";

$pages = ceil($rows/$max_results);

for($i = 0; $i <= ($pages); $i++)
{
$PageStart = $max_results*$i;

$i2 = $i + 1;

if($PageStart == $Start)
{
$links[] = " <span class=RedLink>$i2</span>\n\t ";
}
elseif($PageStart < $rows)
{
$links[] = " <a class=BlackLink href=\"search.php?Start=$PageStart&c=$_GET[c]&AgentID=$_GET[AgentID]&search_city=$_GET[search_city]&search_state=$_GET[search_state]&search_country=$_GET[search_country]&min=$_GET[min]&max=$_GET[max]&year1=$_GET[year1]&year2=$_GET[year2]&SelectMake=$_GET[SelectMake]&vehicle=$_GET[vehicle]&p=$_GET[p]&r=$_GET[r]\">$i2</a>\n\t ";
}
}

$links2 = implode(" | ", $links);

$ListingTable .= $links2;

$ListingTable .= "| </td>";

$ListingTable .= "</table><br>\n";

}
}
else
{
$ListingTable = "<br><br><center>Non è stato trovato alcun risultato corrispondente alla ricerca.</center>";
}

require_once("templates/HeaderTemplate.php");
require_once("templates/introIII.php");
require_once("templates/SearchTemplate.php");
require_once("templates/FooterTemplate.php");

?>



Ringrazio anticipatamente chiunque vorrà darmi una mano.
 
Discussioni simili
Autore Titolo Forum Risposte Data
D [risolto] Problemi di paginazione dei risultati con una determinata query Classic ASP 4
K problemi con paginazione tabella PHP 7
T problemi con dati menu a tendina HTML e CSS 2
M Upload immagine con javascript problemi con FormData() Javascript 1
A Problemi con move_uploaded_file PHP 7
M Problemi con la stampa dei valori in php PHP 1
L Problemi con il login PHP 2
R Tutto su utf-8 ma ancora problemi con i caratteri speciali in mysql MySQL 1
Z problemi con foreach insert into PHP 10
B javascript per problemi con pdf e Safari Javascript 0
M Problemi con creazione maschere Presentati al Forum 1
M Problemi con query a più tabelle PHP 3
S Problemi delle funzioni eliminate con PHP e MySQL PHP 4
M Problemi con blog Grav CMS (Content Management System) 0
S incoerenza di stampa. problemi con il magenta Photoshop 3
A problemi con paypall Java 1
S Problemi con modulo upload video php (help!) PHP 0
felino [Windows 8.1] Problemi con connessione WiFi Windows e Software 0
E [PHP] problemi nuova riga con fwrite su piattaforma android PHP 5
O [HTML] problemi con la regola "background-attachment: fixed" in EDGE HTML e CSS 0
M [PHP] Problemi con query unione PHP 11
M [PHP] Problemi con select PHP 6
ANDREA20 [HTML] problemi con il footer HTML e CSS 1
D [MS Access] problemi con inserimento campo in una maschera MS Access 6
M [PHP] Problemi con il riconoscimento login. PHP 21
A [WordPress] problemi con xampp WordPress 2
M Problemi con database Apache/2.4.37 (Win32) OpenSSL/1.1.1a PHP/7.3.1 PHP 6
S [PHP] problemi con le sessioni PHP 3
T [PHP] problemi con il browser PHP 0
Andrea_Ventura [HTML] Problemi con effetto hover HTML e CSS 5
M [PHP] Problemi con login facebook PHP 0
Andrea_Ventura [HTML] Problemi con visualizzazione Navigation Bar HTML e CSS 10
andreas88 Creare file .htaccess per risolvere alcuni problemi con il tester SEO SEO e Posizionamento 0
Eugene [Joomla] Problemi con modulo per strutture alberghiere JHotelreservation starter Joomla 6
F [PHP] Problemi di base con bot di telegram PHP 9
M [Photoshop] Problemi con importazione immagini trasparenti in indesign Photoshop 0
E [Photoshop] Problemi con dimensioni immagini Photoshop 12
G [HTML] Problemi con inserimento immagini HTML e CSS 7
L Problemi con Javascript e Mustache Javascript 0
G Invio Mail con PHPMailer, problemi SMTP PHP 7
A [Javascript] problemi con javascrip e posizione GPS html5 Javascript 6
D Due problemi con Photoshop... Photoshop 1
G Problemi con pagina online.php di una chat in php PHP 38
S Problemi con impostazioni php PHP 3
P Problemi con AndroidStudio Sviluppo app per Android 0
S Problemi con Dell Precision T5400 Windows e Software 2
F ciao, sono ferro e ho bisogno di aiuto per problemi con la mail di alice.it Presentati al Forum 1
S [PHP] Problemi con Login e pagina Utente PHP 5
Z problemi con swf e chrome o sistemi portatili Webdesign e Grafica 5
N Problemi connettività con Tp Link EAP 110 Reti LAN e Wireless 0

Discussioni simili