Populating Lists
Results 1 to 3 of 3

Thread: Populating Lists

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    5

    Populating Lists

    I am using sql to connect to a database and then php to populate list from it, as you can see the second list is populated the decision of the first, now what Im trying to do is when a user selects from the second list I would like to fire a php statement which puts the result in one table -

    PHP Code:
    <p>please select a store.</p>
      <select name="menu" id="myStore">
       <?php 
        
    include("scripts/dbconnect.php"); 
        
    $query="select distinct store from game order by store asc";
        
    $result=mysql_query($query);
        
    $numrows=mysql_num_rows($result);
        while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)){
         echo 
    '<option value="'.$row['store'].'">'.$row['store'].'</option>';
        }  
       
    ?>
       </select><input type="button" onclick="getStore()" value="Submit" /><br/>

       <?php
        
    if(isset($_GET['myStore'])){
         echo 
    '<p>Select a game.</p>';
         echo 
    '<select name="menu" id="myGame">';
         include(
    "scripts/dbconnect.php"); 
         
    $myStore=$_GET['myStore'];
         
    $query="select description from game where store='$myStore'";
         
    $result=mysql_query($query);
         
    $numrows=mysql_num_rows($result);
         while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)){
           echo 
    '<option value="'.$row['description'].'">'.$row['description'].'</option>';
         } 
         echo 
    '</select>';
         echo 
    '<input type="button" table()" value="Submit" /><br/>';
        }
       
    ?>
    THIS IS WORKING ALL FINE ^^^^^^^^^^^^^^^^^^^^^^

    so based on the decision of the 2nd list I would like to fire this statement below and put the answer in a table -
    PHP Code:
       <?php
        
    if(isset($_GET['myGame'])){
         include(
    "scripts/dbconnect.php"); 
         
    $myGame=$_GET['myGame'];
         
    $query="select id from game where description='$myGame'";
         
    $result=mysql_query($query);

    print 
    "<table border='1'>";
    while (
    $a mysql_fetch_array($res)){
      print 
    "<tr>
            <td>
    $a[0]</td>
        </tr>"
    ;  }
    print 
    "</table>";


        }
       
    ?>
    I know this is a lot to take in, I appreciate any help, thank you

  2. #2
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,767
    I wonder if
    PHP Code:
          echo '<input type="button" table()" value="Submit" /><br/>'
    is causing the problem. You seem to have a stray table()" maybe you meant to do onchange="gettable()" or something similar?

    Also this script is very vulnerable to SQL injection. More on that -> http://us3.php.net/manual/en/securit...-injection.php

    You also never check to verify that the query returns any results before trying to use it. See the link in my signature about mysql errors to see how you should be checking for this.
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,398
    Since you're talking about client-side behavior, you're going to have to use a client-side scripting language. So... either submit the form when the first dropdown selection is made, or use something like AJAX to make a background request to a PHP script that receives input and returns options to be used in the second dropdown.

    For the latter, try searching for phrases like "AJAX chained dropdown" or "AJAX chained select" or something of that nature.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •