Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    Risultati di una queri in tabella

    io ho questa query:

    Codice PHP:
    <?
    include("config.inc.php");
    include(
    "connect.inc.php");
    $query   =   "SELECT   id, marca, modello, prezzo, anno, kw, colore, km, optional   FROM   usato   ORDER   BY   id ";
    $result   =   mysql_query($query,   $db);
    while   (
    $row   =   mysql_fetch_array($result))
    {
        
    //così dovrei passare i dati alle variabili??????????????

            
    $nome1 htmlentities($row['marca']);
        
    $nome2 htmlentities($row['modello']);
        
    $nome3 htmlentities($row['prezzo']);
        
    $nome4 htmlentities($row['anno']);
        
    $nome5 htmlentities($row['kw']);
        
    $nome6 htmlentities($row['colore']);
        
    $nome7 htmlentities($row['km']);
        
    $nome8 htmlentities($row['optional']);

    }
    include(
    "tabella.htm");

    mysql_close($db);
    ?>
    Vorrei che i risultati venissero salvati in questa tabella:
    codice:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="it">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>MARCA</title>
    </head>
    
    <body>
    
    <table border="1" width="100%" id="table1">
    	<tr>
    		<td>MARCA</td>
    		<td>MODELLO</td>
    		<td>PREZZO</td>
    		<td>ANNO</td>
    		<td>KW</td>
    		<td>COLORE</td>
    		<td>KM</td>
    		<td>OPTIONALS</td>
    	</tr>
    	<tr>
    		<td>&lt;?php echo $row[$nome1] ?&gt;</td>
    		<td>&lt;?php echo [$nome2]?&gt;</td>
    		<td>&lt;?php echo $row[nome3] ?&gt;</td>
    		<td>&lt;?php echo [nome4] ?&gt;</td>
    		<td>&lt;?php echo $nome5 ?&gt;</td>
    		<td>&lt;?php echo nome6; ?&gt;</td>
    		<td>&lt;?php echo $row[$nome7] ?&gt;</td>
    		<td>&lt;?php echo $row[nome8] ?&gt;</td>
    	</tr>
    </table>
    
    </body>
    
    </html>
    nei campi della tabella ho provato tutto
    VVoVe:
    Cosa sbaglio???

  2. #2
    Codice PHP:
    [...cut...]
    while   (
    $row   =   mysql_fetch_array($result))  { 
         print 
    '<tr>
                    <td>'
    .htmlentities($row['marca']).'</td>
                    <td>'
    .htmlentities($row['modello']).'</td>
                    <td>'
    .htmlentities($row['prezzo']).'</td>
                    <td>'
    .htmlentities($row['anno']).'</td>
                    <td>'
    .htmlentities($row['kw']).'</td>
                    <td>'
    .htmlentities($row['colore']).'</td>
                    <td>'
    .htmlentities($row['km']).'</td>
                    <td>'
    .htmlentities($row['optional']).'</td>
               </tr>'
    ;

    [...
    cut...] 

  3. #3
    ok perfetto pero' io vorrei che i dati venissero riportati nella tabella html

  4. #4
    costruisci la tabella html attorno al codice che ho postato (ci sono due [...cut...] prima e dopo il mio codice). in pratica prendi l'html da te postato, e metti il mio codice php al posto di questo blocco:

    codice:
    	<tr>
    		<td>&lt;?php echo $row[$nome1] ?&gt;</td>
    		<td>&lt;?php echo [$nome2]?&gt;</td>
    		<td>&lt;?php echo $row[nome3] ?&gt;</td>
    		<td>&lt;?php echo [nome4] ?&gt;</td>
    		<td>&lt;?php echo $nome5 ?&gt;</td>
    		<td>&lt;?php echo nome6; ?&gt;</td>
    		<td>&lt;?php echo $row[$nome7] ?&gt;</td>
    		<td>&lt;?php echo $row[nome8] ?&gt;</td>
    	</tr>

  5. #5
    allora ho modificato il file tabella cosi;

    codice:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="it">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>MARCA</title>
    </head>
    
    <body>
    
    <table border="1" width="100%" id="table1">
    	<tr>
    		<td>MARCA</td>
    		<td>MODELLO</td>
    		<td>PREZZO</td>
    		<td>ANNO</td>
    		<td>KW</td>
    		<td>COLORE</td>
    		<td>KM</td>
    		<td>OPTIONALS</td>
    	</tr>
    	
    	<tr>
    	            <td>'.htmlentities($row['marca']).'</td>
                    <td>'.htmlentities($row['modello']).'</td>
                    <td>'.htmlentities($row['prezzo']).'</td>
                    <td>'.htmlentities($row['anno']).'</td>
                    <td>'.htmlentities($row['kw']).'</td>
                    <td>'.htmlentities($row['colore']).'</td>
                    <td>'.htmlentities($row['km']).'</td>
                    <td>'.htmlentities($row['optional']).'</td>
         	</tr>
    </table>
    </body>
    
    </html>
    e l' index.php

    codice:
    <?
    include("config.inc.php");
    include("connect.inc.php");
    $query   =   "SELECT   id, marca, modello, prezzo, anno, kw, colore, km, optional   FROM   usato   ORDER   BY   id ";
    $result   =   mysql_query($query,   $db);
    $dati = array();
    while($row = mysql_fetch_assoc($result))
    {
      print '<tr>
                    <td>'.htmlentities($row['marca']).'</td>
                    <td>'.htmlentities($row['modello']).'</td>
                    <td>'.htmlentities($row['prezzo']).'</td>
                    <td>'.htmlentities($row['anno']).'</td>
                    <td>'.htmlentities($row['kw']).'</td>
                    <td>'.htmlentities($row['colore']).'</td>
                    <td>'.htmlentities($row['km']).'</td>
                    <td>'.htmlentities($row['optional']).'</td>
               </tr>'; 
    }
    include("tabella.htm");
    
    mysql_close($db);
    ?>
    nei campi della tabella vedo

    MARCA MODELLO PREZZO ANNO KW COLORE KM OPTIONALS
    '.htmlentities($row['marca']).' '.htmlentities($row['modello']).' '.htmlentities($row['prezzo']).' '.htmlentities($row['anno']).' '.htmlentities($row['kw']).' '.htmlentities($row['colore']).' '.htmlentities($row['km']).' '.htmlentities($row['optional']).'

  6. #6
    perchè hai scisso le due cose?

    Codice PHP:
    <html>

    <head>
    <meta http-equiv="Content-Language" content="it">
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>MARCA</title>
    </head>

    <body>

    <table border="1" width="100%" id="table1">
        <tr>
            <td>MARCA</td>
            <td>MODELLO</td>
            <td>PREZZO</td>
            <td>ANNO</td>
            <td>KW</td>
            <td>COLORE</td>
            <td>KM</td>
            <td>OPTIONALS</td>
        </tr>
        
    <?
    include("config.inc.php");
    include(
    "connect.inc.php");
    $query   =   "SELECT   id, marca, modello, prezzo, anno, kw, colore, km, optional   FROM   usato   ORDER   BY   id ";
    $result   =   mysql_query($query,   $db);
    $dati = array();
    while(
    $row mysql_fetch_assoc($result))
    {
      print 
    '<tr>
                    <td>'
    .htmlentities($row['marca']).'</td>
                    <td>'
    .htmlentities($row['modello']).'</td>
                    <td>'
    .htmlentities($row['prezzo']).'</td>
                    <td>'
    .htmlentities($row['anno']).'</td>
                    <td>'
    .htmlentities($row['kw']).'</td>
                    <td>'
    .htmlentities($row['colore']).'</td>
                    <td>'
    .htmlentities($row['km']).'</td>
                    <td>'
    .htmlentities($row['optional']).'</td>
               </tr>'

    }
    include(
    "tabella.htm");

    mysql_close($db);
    ?>
    </table>
    </body>

    </html>

  7. #7
    perche' volevo creare la tabella in htm e richiamarla dall'index.php

    Codice PHP:
    <?
    include("config.inc.php");
    include(
    "connect.inc.php");
    $query   =   "SELECT   id, marca, modello, prezzo, anno, kw, colore, km, optional   FROM   usato   ORDER   BY   id ";
    $result   =   mysql_query($query,   $db);
    $dati = array();
    while(
    $tmp mysql_fetch_assoc($result))
    {
       
    $tmp['marca'] = htmlentities($tmp['marca']);
       
    $tmp['modello'] = htmlentities($tmp['modello']);
       
    $tmp['prezzo'] = htmlentities($tmp['prezzo']);
       
    $tmp['anno'] = htmlentities($tmp['anno']);
       
    $tmp['kw'] = htmlentities($tmp['kw']);
       
    $tmp['colore'] = htmlentities($tmp['colore']);
       
    $tmp['km'] = htmlentities($tmp['km']);
       
    $tmp['optional'] = htmlentities($tmp['optional']);
    $dati[] = $tmp;
    }
    include(
    "tabella.htm");

    mysql_close($db);
    ?>
    Codice PHP:
    <html>

    <
    head>
    <
    meta http-equiv="Content-Language" content="it">
    <
    meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <
    meta name="ProgId" content="FrontPage.Editor.Document">
    <
    meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <
    title>MARCA</title>
    </
    head>

    <
    body>

    <
    table border="1" width="100%" id="table1">
        <
    tr>
            <
    td>MARCA</td>
            <
    td>MODELLO</td>
            <
    td>PREZZO</td>
            <
    td>ANNO</td>
            <
    td>KW</td>
            <
    td>COLORE</td>
            <
    td>KM</td>
            <
    td>OPTIONALS</td>
        </
    tr>
        <
    tr>
            <
    td>&lt;?php echo $dati['marca']; ?&gt;</td>
            <
    td>&lt;?php echo $tmp['modello']; ?&gt;</td>
            <
    td>&lt;?php echo $dati['prezzo'] ?&gt;</td>
            <
    td>&lt;?php echo $dati['anno'] ?&gt;</td>
            <
    td>&lt;?php echo $dati['kw'] ?&gt;</td>
            <
    td>&lt;?php echo $dati['colore'] ?&gt;</td>
            <
    td>&lt;?php echo $dati['km'] ?&gt;</td>
            <
    td>&lt;?php echo $dati['optional'] ?&gt;</td>
        </
    tr>
    </
    table>

    </
    body>

    </
    html
    ma non mi funziona
    comunque facendo come mi hai indicato funziona

  8. #8
    Come avrai capito non sono molto pratico di php...
    perche' in questa riga <td>'.htmlentities($row['marca']).'</td> hai messo il punto all'inizio e subito dopo aver chiuso la parentesi tonda?

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.