Carissimi,
ho iniziato a studiare PHP + MySQL e mi sono fatto aiutare da Dreamweaver per creare un accesso alla tabella del database (un archivio con i CAP e i prefissi telefonici dei comuni italiani).
Ho creato una Query per i nomi di comune contenenti "torre".
Quando ho seguito le istruzioni per visualizzare le 10 righe di ogni pagina, viene creata un'Area ripetuta per la riga della tabella dinamica ma, quando vado a visualizzarla dal vivo, viene presentata una sola riga.
Poi, andando a confrontare il codice con altri per simili scopi, sui vari forum PHP, ho realizzato che Dreamweaver avvia una connessione persistente al Database mentre, nei vari forum, ho visto che le soluzioni sono sempre basate su apertura e chiusura della connessione.
Potete aiutarmi a capire il perché della scelta di Dreamweaver e come mai il codice non mostra le 10 righe del recordset?
Grazie anticipatamente
Carmine
<?php virtual('/Connections/locale.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_RecordsetCAPtel = 10;
$pageNum_RecordsetCAPtel = 0;
if (isset($_GET['pageNum_RecordsetCAPtel'])) {
$pageNum_RecordsetCAPtel = $_GET['pageNum_RecordsetCAPtel'];
}
$startRow_RecordsetCAPtel = $pageNum_RecordsetCAPtel * $maxRows_RecordsetCAPtel;
mysql_select_db($database_locale, $locale);
$query_RecordsetCAPtel = "SELECT * FROM CAPtel WHERE Comune LIKE '%torre%'";
$query_limit_RecordsetCAPtel = sprintf("%s LIMIT %d, %d", $query_RecordsetCAPtel, $startRow_RecordsetCAPtel, $maxRows_RecordsetCAPtel);
$RecordsetCAPtel = mysql_query($query_limit_RecordsetCAPtel, $locale) or die(mysql_error());
$row_RecordsetCAPtel = mysql_fetch_assoc($RecordsetCAPtel);
if (isset($_GET['totalRows_RecordsetCAPtel'])) {
$totalRows_RecordsetCAPtel = $_GET['totalRows_RecordsetCAPtel'];
} else {
$all_RecordsetCAPtel = mysql_query($query_RecordsetCAPtel);
$totalRows_RecordsetCAPtel = mysql_num_rows($all_RecordsetCAPtel);
}
$totalPages_RecordsetCAPtel = ceil($totalRows_RecordsetCAPtel/$maxRows_RecordsetCAPtel)-1;
$queryString_RecordsetCAPtel = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_RecordsetCAPtel") == false &&
stristr($param, "totalRows_RecordsetCAPtel") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_RecordsetCAPtel = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_RecordsetCAPtel = sprintf("&totalRows_RecordsetCAPtel=%d%s", $totalRows_RecordsetCAPtel, $queryString_RecordsetCAPtel);
mysql_free_result($RecordsetCAPtel);
?>
<table border="1" cellpadding="2" cellspacing="2">
<tr>
<td>Comune</td>
<td>Provincia</td>
<td>Regione</td>
<td>CAP</td>
<td>Prefisso</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_RecordsetCAPtel['Comune']; ?></td>
<td><?php echo $row_RecordsetCAPtel['Provincia']; ?></td>
<td><?php echo $row_RecordsetCAPtel['Regione']; ?></td>
<td><?php echo $row_RecordsetCAPtel['CAP']; ?></td>
<td><?php echo $row_RecordsetCAPtel['Prefisso']; ?></td>
</tr>
<?php } while ($row_RecordsetCAPtel = mysql_fetch_assoc($RecordsetCAPtel)); ?>
</table>