Visualizzazione dei risultati da 1 a 4 su 4

Discussione: problema con script

  1. #1

    problema con script

    ciao a tutti...
    io ho elaborato questo script ke xò nn funge x come dovrebbe
    Codice PHP:
    <?php
          
    require "db_conn.php";
        
    $query "SELECT * FROM sondaggio";
    $result mysql_query($query$db_connect) or die("Errore...");
    $array mysql_fetch_array($result);
    $domanda$array[1];
    $numrows mysql_num_rows($result);
    print 
    "<table height=237 bgcolor=#993333>
            <tr>
              <th rowspan=\"2\" width=\"1\"></th>
              <th width=\"138\" height=\"23\"><span class=\"Stile1\">Sondaggio </span></th>
              <th rowspan=\"2\" width=\"1\"></th>
            </tr>
             <th height=\"185\"> <table bgcolor=\"#000000\" width=\"138\" height=\"198\">
                  <tr>
                    <th height=\"37\" colspan=\"2\"><span class=\"Stile1\">
    $domanda</span></th>
                  </tr>
                  <form action=\"scriptso.php\" method=\"post\" name=\"sondaggio\" id=\"sondaggio\">"
    ;
                    
    {
    for(
    $x=0$x<$numrows$x++){
    $resrow mysql_fetch_row($result);
    $id $resrow[0];
    $opzione $resrow[2];
    $voti $resrow[3];
    print 
    "<tr>
                      <th width=\"34\"><input name=voto type=radio id=
    $id value=$opzione /></th>
                      <th height=\"26\"><span class=Stile1>
    $opzione</span></th>
           </tr>"
    ;

    }
    };
    print 
    "<tr>
                      <th height=\"27\"><span class=\"Stile1\"></span></th>
                      <th width=\"92\"><input name=\"submit\" type=\"image\" src=\"grafica/button.gif\" alt=\"vota\" /></th>
           </tr>
          </form>
              </table>
            </th>
            </tr>
            <tr width=\"4\">
              <th height=\"4\" colspan=\"3\" ></th>
            </tr>
          </table>"
    ;
          
    ?>
    il risultato di questo script lo si può trovare QUI
    sarebbe lo script del sondaggio solo ke nn riesco a far prelevare la prima opzione dal database infatti l'ultimo campo del sondaggio rimane vuoto e senza valore!!
    Dov'è l'errore????
    GRAZIE

  2. #2
    il primo record lo hai già letto con la chiamata a mysql_fetch_array. Il puntatore si è spostato e nel ciclo for next parti dal secondo.
    Tra parentesi il ciclo lo farei così

    while ($row=mysql_fetch_array($result)) {
    $mio_campo = $row["nome_del_campo"];
    ....
    }

    ecc. ecc.
    ciao
    sergio

  3. #3
    Se scrivi:
    Codice PHP:
    <?php
          
    require "db_conn.php";
        
    $query "SELECT * FROM sondaggio";
    $result mysql_query($query$db_connect) or die("Errore...");
    $array mysql_fetch_array($result);
    $domanda$array[1];
    $numrows mysql_num_rows($result);
    ti sei "mangiato" la prima riga!!!
    infatti $array[0] contiene l'id della prima riga, $array[2] l'opzione e $array[3] i voti

    quindi, considerando questo, il codice potrà essere:
    Codice PHP:
    <?php
          
    require "db_conn.php";
        
    $query "SELECT * FROM sondaggio";
    $result mysql_query($query$db_connect) or die("Errore...");
    $array mysql_fetch_array($result);
    $domanda$array[1];
    $numrows mysql_num_rows($result);
    print 
    "<table height=237 bgcolor=#993333>
            <tr>
              <th rowspan=\"2\" width=\"1\"></th>
              <th width=\"138\" height=\"23\"><span class=\"Stile1\">Sondaggio </span></th>
              <th rowspan=\"2\" width=\"1\"></th>
            </tr>
             <th height=\"185\"> <table bgcolor=\"#000000\" width=\"138\" height=\"198\">
                  <tr>
                    <th height=\"37\" colspan=\"2\"><span class=\"Stile1\">
    $domanda</span></th>
                  </tr>
                  <form action=\"scriptso.php\" method=\"post\" name=\"sondaggio\" id=\"sondaggio\">"
    ;
    // Scrivo i dati della prima riga, che ho già 'in canna'
    $id $array[0];
    $opzione $array[2];
    $voti $array[3];
    print 
    "<tr>
                      <th width=\"34\"><input name=voto type=radio id=
    $id value=$opzione /></th>
                      <th height=\"26\"><span class=Stile1>
    $opzione</span></th>
           </tr>"
    ;

                    
    {
    for(
    $x=1$x<$numrows$x++){  //ATTENZIONE! da 1 non da 0
    $resrow mysql_fetch_row($result);
    $id $resrow[0];
    $opzione $resrow[2];
    $voti $resrow[3];
    print 
    "<tr>
                      <th width=\"34\"><input name=voto type=radio id=
    $id value=$opzione /></th>
                      <th height=\"26\"><span class=Stile1>
    $opzione</span></th>
           </tr>"
    ;

    }
    };
    print 
    "<tr>
                      <th height=\"27\"><span class=\"Stile1\"></span></th>
                      <th width=\"92\"><input name=\"submit\" type=\"image\" src=\"grafica/button.gif\" alt=\"vota\" /></th>
           </tr>
          </form>
              </table>
            </th>
            </tr>
            <tr width=\"4\">
              <th height=\"4\" colspan=\"3\" ></th>
            </tr>
          </table>"
    ;
          
    ?>
    HTH
    Zappa
    [PC:Presario 2515EU][Cpu:P4@2.3GHz][Ram: 512M][HDU:80G@5400 RPM]
    [Wireless:LinkSys][OS: Ubuntu 9.04 - Jaunty Jackalope]

  4. #4
    Grazie mille a entrambi sono tutti e due consigli perfetti!!!!!

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 © 2024 vBulletin Solutions, Inc. All rights reserved.