ciao a tutti, è da qualche setimana che mi sono affacciato al mondo di php e stamane mi sono imbattuto per la prima volta nella paginazione dei record. Non riesco a capire perchè dopo aver estratto il primo set di record con la clausola LIMIT non riesco a sfogliare i dati (avanti>> e indietro<<) eppure il codice mi sembra corretto
, qualcuno potrebbe darci un'occhiata? Grazie anticipatamente.
Codice PHP:
<?php require_once('Connections/data_connetion_db1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Recordset1 = 30;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($database_data_connetion_db1, $data_connetion_db1);
$query_Record = "SELECT * FROM intrauserfatture WHERE ";
$clausola_where = "";
?>
<?php
mysql_select_db($database_data_connetion_db1, $data_connetion_db1);
$query_Record = "SELECT * FROM intrauserfatture WHERE ";
$clausola_where = "";
$clausola_where .= (isset($_POST['anno']) && $_POST['anno'] !='')? "anno BETWEEN 1960 AND 2010" ." ":"";;
$clausola_where .= (isset($senzs[1]) && $senzs !='')? "AND protocollo_iva <'".mysql_escape_string($senzs[1])."' ":"";
$clausola_where .= (isset($_POST['protocollo_iva']) && $_POST['protocollo_iva'] !='')? "AND protocollo_iva='".mysql_escape_string($_POST['protocollo_iva'])."' ":"";
$clausola_where .= (isset($_POST['data_doc']) && $_POST['data_doc'] !='')? "AND data_doc='".$datasearch."' ":"";
$clausola_where .= (isset($_POST['numero_doc']) && $_POST['numero_doc'] !='')? "AND numero_doc BETWEEN $splitnum[0] AND $numdocmenopunto" ." ":"";;
}
$query_Recordset1 = $query_Record.$clausola_where;
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $data_connetion_db1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1,$queryString_Recordset1);
?>
<table border="0" align="center" cellpadding="1" cellspacing="1" class="bodystyle">
<tr class="Stile2">
<td><div align="center">Id</div></td>
<td><div align="center">anno</div></td>
<td><div align="center">protocollo_iva</div></td>
<td><div align="center">numero_doc</div></td>
<td><div align="center">data_doc</div></td>
<td><div align="center">tot_importo</div></td>
<td><div align="center">ragione_sociale</div></td>
<td><div align="center">tipo_movimento</div></td>
<td><div align="center">vedi_doc</div></td>
<td><div align="center">vedi_all</div></td>
<td><div align="center">codice</div></td>
</tr>
<?php
if ($row_Recordset1 != NULL)
do { ?>
<tr class="stile3">
<td><?php echo $row_Recordset1['Id']; ?></td>
<td><?php echo $row_Recordset1['anno']; ?></td>
<td><?php echo $row_Recordset1['protocollo_iva']; ?></td>
<td><?php echo $row_Recordset1['numero_doc']; ?></td>
<td><?php echo date('d/m/Y', strtotime($row_Recordset1['data_doc']));?></td>
<td><?php echo $row_Recordset1['tot_importo']; ?></td>
<td><?php echo $row_Recordset1['ragione_sociale']; ?></td>
<td><?php echo $row_Recordset1['tipo_movimento']; ?></td>
<td><?php echo $row_Recordset1['vedi_doc']; ?></td>
<td><?php echo $row_Recordset1['vedi_all']; ?></td>
<td><?php echo $row_Recordset1['codice']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</tr>
<tr class="Stile18">
<td><table border="0" align="center">
<tr class="stile3Copia">
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
[b][b][url="<?php printf("]">Primo[/url]
<?php } // Show if not first page ?>
[/b][/b]</td>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
[b][b][url="<?php printf("]">Indietro[/url]
<?php } // Show if not first page ?>
[/b][/b]</td>
<td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
[b][b][url="<?php printf("]">Avanti[/url]
<?php } // Show if not last page ?>
[/b][/b]</td>
<td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
[b][b][url="<?php printf("]">Ultimo[/url]
<?php } // Show if not last page ?>
[/b][/b]</td>
</tr>
</table></td>
</tr>
<tr class="Stile18">
<td class="Stile17"><div align="center" class="stile3">Record da [b]<?php echo ($startRow_Recordset1 + 1) ?>[/b] a [b]<?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?>[/b] su [b]<?php echo $totalRows_Recordset1 ?> [/b]</div></td>
</tr>
<tr class="Stile1CopiaCopia"></tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>