Visualizzazione dei risultati da 1 a 3 su 3

Discussione: pagina ricerca in php

  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    332

    pagina ricerca in php

    Salve creando una pagina di ricerca per estrarre dati database, composta da un form contenenti 2 campi (marca e modello) e relativo pulsante invio; se inserisco nel campo marca (esempio:ford)
    mi appare la lista completa dei ford se invece aggiungo un modello specifico esempio (ka) non viene visualizzato solo il modello scelto ma tutti i modelli; che codice devo aggiungere per visualizzare solo quel modello??? grazie

  2. #2

    Re: pagina ricerca in php

    Originariamente inviato da GLORIA71
    Salve creando una pagina di ricerca per estrarre dati database, composta da un form contenenti 2 campi (marca e modello) e relativo pulsante invio; se inserisco nel campo marca (esempio:ford)
    mi appare la lista completa dei ford se invece aggiungo un modello specifico esempio (ka) non viene visualizzato solo il modello scelto ma tutti i modelli; che codice devo aggiungere per visualizzare solo quel modello??? grazie
    Aspetta che consulto la sfera di cristallo!

    Un po' di codice e magari la query attuale non guasterebbe.
    "Mai discutere con un idiota. Ti trascina al suo livello e ti batte con l'esperienza." (Oscar Wilde)

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2002
    Messaggi
    332
    ecco il codice ::agina di ricerca::
    <!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>
    </head>

    <body>
    <form id="form1" name="form1" method="post" action="risposta.php">
    <label>marca
    <input name="marca" type="text" id="marca" />
    </label>
    <label>modello
    <input name="modello" type="text" id="modello" />
    </label>
    <label>cerca
    <input type="submit" name="cerca" id="cerca" value="Invia" />
    </label>
    </form>
    </body>
    </html>



    pagina risultato:::

    <?php require_once('Connections/beatrice.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_Recordset1 = "-1";
    if (isset($_POST['marca'])) {
    $colname_Recordset1 = $_POST['marca'];
    }
    mysql_select_db($database_beatrice, $beatrice);
    $query_Recordset1 = sprintf("SELECT * FROM modelli WHERE marca = %s ORDER BY foto ASC", GetSQLValueString($colname_Recordset1, "text"));
    $Recordset1 = mysql_query($query_Recordset1, $beatrice) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);
    ?><!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>
    </head>

    <body>
    <table border="1" cellpadding="3" cellspacing="3">
    <?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?>
    <tr bgcolor="#FFFF66">
    <td>foto</td>
    <td>id</td>
    <td>marca</td>
    <td>modello</td>
    <td>prezzo</td>
    <td>anno</td>
    <td>cc</td>
    <td>alimentazione</td>
    <td>colore</td>
    <td>km</td>
    </tr>
    <?php } // Show if recordset not empty ?>

    <?php do { ?>
    <tr bgcolor="#FF99CC">
    <td><?php echo $row_Recordset1['foto']; ?></td>
    <td><?php echo $row_Recordset1['id']; ?></td>
    <td><?php echo $row_Recordset1['marca']; ?></td>
    <td><?php echo $row_Recordset1['modello']; ?></td>
    <td><?php echo $row_Recordset1['prezzo']; ?></td>
    <td><?php echo $row_Recordset1['anno']; ?></td>
    <td><?php echo $row_Recordset1['cc']; ?></td>
    <td><?php echo $row_Recordset1['alimentazione']; ?></td>
    <td><?php echo $row_Recordset1['colore']; ?></td>
    <td><?php echo $row_Recordset1['km']; ?></td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
    </table>


    <?php if ($totalRows_Recordset1 == 0) { // Show if recordset empty ?>


    spiacenti nessun risultato</p>
    <?php } // Show if recordset empty ?>
    </body>
    </html>
    <?php
    mysql_free_result($Recordset1);
    ?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.