Newsgroup: it.comp.www.php
Titolo: più campi di ricerca

Ciao a tutti,
Nel caso dovessi avere più campi di ricerca come imposto la pagina ciao.php?
 
Grazie
 
Mi puoi aiutare gentilmente ?
 
<title>Documento senza titolo</title>
</head>
 
<body>
<form id="form" name="form" method="post" action="ciao.php">
   <label>cerca
   <input type="text" name="cerca1" id="cerca" />
   </label>
   <label></label>
     <label><br />
     cerca
   <input type="text" name="cerca2" id="cerca" />
   </label>
    <label><br />
     cerca
   <input type="text" name="cerca2" id="cerca" />
   </label>
     <label>
      <label><br />
     cerca
   <input type="text" name="cerca3" id="cerca" />
   </label>
    <label><br />
     cerca
   <input type="text" name="cerca4" id="cerca" />
   </label>
    <label><br />
     cerca
   <input type="text" name="cerca5" id="cerca" />
   </label>
    <label><br />
     cerca
   <input type="text" name="cerca6" id="cerca" />
   </label>
    <label><br />
     cerca
   <input type="text" name="cerca7" id="cerca" />
   </label> <label><br />
     cerca
   <input type="text" name="cerca8" id="cerca" />
   </label> <label><br />
     cerca
   <input type="text" name="cerca9" id="cerca" />
   </label> <label><br />
     cerca
   <input type="text" name="cerca10" id="cerca" />
   </label> <label><br />
     cerca
   <input type="text" name="cerca11" id="cerca" />
   </label> <label><br />
     cerca
   <input type="text" name="cerca12" id="cerca" />
   </label> <label><br />
     cerca
   <input type="text" name="cerca13" id="cerca" />
   </label> <label><br />
     cerca
   <input type="text" name="cerca14" id="cerca" />
   </label>
    <label><br />
     cerca
   <input type="text" name="cerca15" id="cerca" />
   </label>
 
   <input type="submit" name="cerca15" id="invia" value="Invia" />
   </label>
 
</form>
<p>&nbsp;</p>
</body>
</html>
 
=========================================================
 
<?php require_once('Connections/conn_db.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;
}
}
 
$colname_telefoni = "-1";
if (isset($_POST['cerca2'])) {
   $colname_telefoni = $_POST['cerca2'];
 
}
mysql_select_db($database_conn_db, $conn_db);
$query_telefoni = sprintf("SELECT * FROM sheet1 WHERE INTERNO = %s", 
GetSQLValueString($colname_telefoni, "int"));
$telefoni = mysql_query($query_telefoni, $conn_db) or die(mysql_error());
$row_telefoni = mysql_fetch_assoc($telefoni);
$totalRows_telefoni = mysql_num_rows($telefoni);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
">
<html xmlns="
http://www.w3.org/1999/xhtml
">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento senza titolo</title>
<style type="text/css">
<!--
body,td,th {
     font-family: Verdana, Arial, Helvetica, sans-serif;
     font-size: 12px;
     color: #FFFFFF;
}
body {
     background-color: #000000;
}
-->
</style></head>
 
<body>
<table width="983" border="1">
   <tr>
     <td width="123">SEDE</td>
     <td width="132">COGNOME</td>
     <td width="104">NOME</td>
     <td width="123">INTERNO</td>
     <td width="97">CRIS</td>
     <td width="91">CPL</td>
     <td width="93">POS</td>
     <td width="76">COPPIA</td>
     <td width="86">PRESA</td>
   </tr>
   <tr>
     <td><?php echo $row_telefoni['SEDE']; ?></td>
     <td><?php echo $row_telefoni['COGNOME']; ?></td>
     <td><?php echo $row_telefoni['NOME']; ?></td>
     <td><?php echo $row_telefoni['INTERNO']; ?></td>
     <td><?php echo $row_telefoni['CRIS']; ?></td>
     <td><?php echo $row_telefoni['CPL']; ?></td>
     <td><?php echo $row_telefoni['POS']; ?></td>
     <td><?php echo $row_telefoni['1A-COPPIA']; ?></td>
     <td><?php echo $row_telefoni['NUMERO PRESA']; ?></td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
   <tr>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
     <td>&nbsp;</td>
   </tr>
</table>
</body>
</html>
<?php
mysql_free_result($telefoni);
?>
 
 

   </label>
 
Gli id, appunto per sono id, devono essere univoci.
Se proprio non puoi fare altrimenti e vuoi usare questo layout, usa un
almeno array con <input name="cerca[]"...>
 
M.
 
 


 
Ma nella pagina ciao.php come li prendo i dati dal form?

 Ma nella pagina ciao.php come li prendo i dati dal form?
 
http://stackoverflow.com/questions/5090055/handling-array-field-post-data
 

 Ma nella pagina ciao.php come li prendo i dati dal form?
 
$cerca = $_POST['cerca']; // ok, andrebbero messi i controlli del caso
 
foreach($cerca as $riga)
{
..
..
}
 
M.