Ecco il codice della pagina.
In rosso sono segnati le due query che mi sballano tutto se metto il WHERE (come ho fatto nell'esempio).
<?
//************************************************** **************************
////////////////////////Downloaded from www.plus2net.com //////////////////////////////////////////
/////////////////////// Visit www.plus2net.com for more such script and codes.
//////// Read the readme file before using /////////////////////
//////////////////////// You can distribute this code with the link to www.plus2net.com ///
///////////////////////// Please don't remove the link to www.plus2net.com ///
//////////////////////////
//************************************************** ***************************
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Plus2net.com paging script in PHP</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style></head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?
require "config.php"; // All database details will be included here
////////// delete for demo///
//require "../tracking/z_db.php";
connecttodb($servername,$dbname,$dbusername,$dbpas sword);
function connecttodb($servername,$dbname,$dbuser,$dbpasswor d)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
$cerca=$_POST['cerca'];
$dato=$_POST['dato'];
$regione=$_POST['regione'];
//////////
$page_name="demo_paging1.php"; // If you use this code with a different page ( or file ) name then change this
if(!isset($start)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$limit = 2; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
echo "<table width=\"100%\">";
echo "<tr>";
echo "<form name=cerca action='' method=post>";
echo "<td >Azienda:<input type=\"text\" name=\"dato\">";
echo "Regione: <select name=\"regione\" id=\"regione\" onchange=\"setCities(this)\">
<option value=\"zz\" selected=\"selected\">------------</option>
<option value=\"abbruzzo\">Abbruzzo</option>
<option value=\"basilicata\">Basilicata</option>
<option value=\"calabria\">Calabria</option>
<option value=\"campania\">Campania</option>
<option value=\"emilia romagna\">Emilia Romagna</option>
<option value=\"friuli venezia giulia\">Friuli Venezia Giulia</option>
<option value=\"lazio\">Lazio</option>
<option value=\"liguria\">Liguria</option>
<option value=\"lombardia\">Lombardia</option>
<option value=\"marche\">Marche</option>
<option value=\"molise\">Molise</option>
<option value=\"piemonte\">Piemonte</option>
<option value=\"bolzano\">Prov. aut. Bolzano</option>
<option value=\"trento\">Prov. aut. Trento</option>
<option value=\"puglia\">Puglia</option>
<option value=\"sardegna\">Sardegna</option>
<option value=\"sicilia\">Sicilia</option>
<option value=\"toscana\">Toscana</option>
<option value=\"umbria\">Umbria</option>
<option value=\"valle d'aosta\">Valle d'Aosta</option>
<option value=\"veneto\">Veneto</option>
</select>";
echo "Settore: <select name=\"settore\" id=\"settore\">
<option value=\"\" selected=\"selected\">---------------</option>
</select>";
echo "<tr><td><input type=\"submit\" value=\"Invia\" name=\"rubrica\">";
echo "<input type=\"reset\" value=\"RESET\" name=\"rubrica\"></FORM></td></tr></TABLE>";
/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2=" SELECT * FROM dop WHERE regione = '$regione' ";
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////
/////////// Now let us print the table headers ////////////////
////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
$query=" SELECT * FROM dop WHERE regione = '$regione' limit $eu, $limit ";
$result=mysql_query($query);
echo mysql_error();
//////////////// Now we will display the returned records in side the rows of the table/////////
while($noticia = mysql_fetch_array($result))
{
if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
else{$bgcolor='#f1f1f1';}
echo "<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#E2E2E2\">Nome Azienda:$noticia[nome_azienda]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#FFFFFF\">Indirizzo: $noticia[indirizzo]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#E2E2E2\">CAP: $noticia[cap]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#FFFFFF\">Città: $noticia[citta]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#E2E2E2\">Regione: $noticia[regione]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#FFFFFF\">Settore: $noticia[settore]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#E2E2E2\">Telefono: $noticia[telefono]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#FFFFFF\">Fax: $noticia[fax]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#E2E2E2\">Email: $noticia[email]</td>
</tr>
</table>";
echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td bgcolor=\"#FFFFFF\">Sito Web: $noticia[sito_web]</td>
</tr>
</table>";
echo "
";}
////////////////////////////// End of displaying the table with records ////////////////////////
///////////////////////////////
if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging
/////////////// Start the bottom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='30%'><tr><td align='left' width='30%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) {
print "<font face='Verdana' size='2'>PREV</font>";
}
//////////////// Let us display the page links at center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <font face='Verdana' size='2'>$l</font> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
$l=$l+1;
}
echo "</td><td align='right' width='30%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) {
print "<font face='Verdana' size='2'>NEXT</font>";}
echo "</td></tr></table>";
}// end of if checking sufficient records are there to display bottom navigational link.
?>