-
stampa singolo record
Codice PHP:
<?php
$username="giacomofabbian";
$password="";
$database="my_giacomofabbian";
$nome=$_POST['nome'];
$cognome=$_POST['cognome'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Impossibile selezionare il database");
$query="SELECT * FROM Agente WHERE nome='$nome' AND cognome='$cognome'";
$risultati=mysql_query($query);
$numrows = mysql_num_rows($risultati);
if ($numrows==0){
echo "Agente non trovato!";
}
else
{
?><table border="2" bgcolor="#e0ffdf">
<tr>
<td>Nome</td>
<td>Cognome</td>
</tr>
<?php for($x=0; $x<$numrows; $x++){
$resrow = mysql_fetch_row($risultati);
$nome = $resrow[1];
$cognome = $resrow[2];
?>
<tr>
<td><?php echo $nome; ?> </td>
<td> <?php echo $cognome; ?> </td>
</tr>
<?php
}?>
</table> <?php
}
può andare questo per stampare un singolo record???
il problema è che finisce sempre per agente non trovato
-
posto la soluzione in caso servisse
Codice PHP:
<html>
<body background="s1.gif">
<?php
$username="giacomofabbian";
$password="";
$database="my_giacomofabbian";
$nome=$_POST['nome'];
//echo $nome;
$cognome=$_POST['cognome'];
//echo $cognome;
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Impossibile selezionare il database");
$result=mysql_query("SELECT * FROM Agenti WHERE nome='".$nome."' AND cognome='".$cognome."'");
while($riga=mysql_fetch_row($result)){
$codag=$riga[0];
$nome=$riga[1];
$cognome=$riga[2];
$nvendite=$riga[3];
echo "<p><strong>codag: </strong>$codag<br />";
echo "<strong>nome: </strong>$nome<br />";
echo "<strong>cognome: </strong>$cognome<br />";
echo "<strong>nvendite: </strong>$nvendite</p>";
}?>
<br><br><input type="button" value="Cerca un altro agente" OnClick="document.location.href='cercaag.htm'">
<br><br><input type="button" value="Torna al menù di statistica" OnClick="document.location.href='homesta.htm'">
<br><br>
<a href="homepage.htm"><img src="casa.gif"></a>
</body>
</html>
il problema stava nella concatenazione delle stringhe nella WHERE