Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 16

Discussione: javascript e php

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    794

    javascript e php

    dovrei fare in modo che cliccando su una categoria di prodotti mi compaiono le sottocategorie associate presenti in un'altra tabella. Premesso che le tabelle sono in mysql e uso php per interrogare il database.
    Vorrei mettere tutto in una sola pagina e di conseguenza usare javascript per la comparsa di una table con le sottocategorie trovate..
    Come posso fare?
    Grazie mille...

  2. #2
    studiare un po' di ajax...

    da php generi un file xml o json che poi parsi con js per riempire dinamicamente la tua tabella...

    non è così difficile trovi parecchio materiale qua su html.it o con google...

    ciao
    « Se nella prima mezz'ora non capisci chi è il pollo, allora il pollo sei tu. » [Thomas "Amarillo Slim" Preston, campione del mondo di poker]

  3. #3
    Codice PHP:
    <html>
    <head><title></title></head>
    <body>
    <?php
       $link
    =mysql_connect('localhost''username''password');
       
    mysql_select_db('database'$link);
       
    $result mysql_query("SELECT * from prodotti ORDER BY Nome");
       if (
    mysql_num_rows($result)) {
         echo 
    "<table border=\"0\" width=\"100%\">";
         while (
    $row=mysql_fetch_assoc($result))
           echo 
    "<tr><td>".$row['Nome']."</td><td>".$row['Prezzo']."</td></tr>";
         echo 
    "</table>";
       }
       
    mysql_free_result($result);
       
    mysql_close($link);
    ?>
    </body>
    </html>

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    794
    Si ho capito ma io volevo fare in modo che cliccando su categorie gia stampate dopo una query mi compaiono le sottocategorie associate. Sempre con il sistema di echo table

  5. #5
    ah scusa beh allora

    <?php
    $id = $_REQUEST['id'];
    if ($id) $id_cat = $_REQUEST['id_cat'];
    ?>
    <html>
    <head><title></title></head>
    <body>
    <form id="tabella" method="post" action="<?=$_SERVER['PHP_SELF']?>?id=1">
    <?php
    $link=mysql_connect('localhost', 'username', 'password');
    mysql_select_db('database', $link);
    if (!$id) {
    $result = mysql_query("SELECT * from categorie ORDER BY Nome");
    if (mysql_num_rows($result)) {
    echo "<table border=\"0\" width=\"100%\"><tr>";
    while ($row=mysql_fetch_assoc($result))
    echo "<td onclick=\"document.forms[0].action='<?=$_SERVER['PHP_SELF']?>?id=1&amp;id_cat=".$row['ID_Cat']."\">".$row['Nome']."</td>";
    echo "</tr></table>";
    }
    } else {
    $result = mysql_query("SELECT * from subCat WHERE ID_Cat=$id_cat ORDER BY Nome");
    echo "<table border=\"0\" width=\"100%\"><tr>";
    if (mysql_num_rows($result)) {
    echo "<table border=\"0\" width=\"100%\"><tr>";
    while ($row=mysql_fetch_assoc($result))
    echo "<td>".$row['Nome']."</td>";
    echo "</tr></table>";
    }
    }
    mysql_free_result($result);
    mysql_close($link);
    ?>
    </form>
    </body>
    </html>

  6. #6
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    794
    mi dà errore di sintassi in corrispondenza di questa riga:

    echo "<td onclick=\"document.forms[0].action='<?=$_SERVER['PHP_SELF']?>?id=1&id_cat=".$row['ID_Cat']."\">".$row['Nome']."</td>";

  7. #7
    infatti mancava un '

    echo "<td onclick=\"document.forms[0].action='<?=$_SERVER['PHP_SELF']?>?id=1&id_cat=".$row['ID_Cat']."'; document.forms[0].submit()\">".$row['Nome']."</td>";

  8. #8
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    794
    ora mi dà quest'errore sempre in corrispondenza dell'istruzione precedente

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in index2.php on line 60

  9. #9
    while ($row=mysql_fetch_assoc($result))
    echo "<td onclick=\"document.forms[0].action=\"<?=$_SERVER['PHP_SELF']?>?id=1&id_cat=".$row['ID_Cat']."\">".$row['Nome']."</td>";

  10. #10
    Utente di HTML.it
    Registrato dal
    Jun 2006
    Messaggi
    794
    mi dà questo errore:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 60

    sempre in corrispondenza della stessa istruzione

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.