Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

list data from db and submit query?

hi everyone,

i am trying tot create the following, but i can't figure out how to do this.

A listbox (list/menu) gets names from db,
user selects a name from the list,
a query is send to db (where InputName=selected name),
output comes in texfields.

The problem for me is the following, how can i get the selected item from the list,
without using PHP_SELF?InputName=etc.

I've got something like this, but it has to function (if possible) without
getting the data from the browser...By the way, below code isn't working, anyway.

Is this possible? Anyone who kows how to this in a proper way?

Thanks in advance,


$result=mysql_query("select * from $dbTable3", $link);
$rowCheck = mysql_num_rows($result);

echo "<form name=\"CityName\" id=\"CityName\" action=\"$PHP_SELF\" method=\"get\">";
echo "<select name=\"InputName\" onchange=document.all.CityName.submit();>";
if($rowCheck > 0){

while($row = mysql_fetch_array($result)){

  //put in list

    echo "<option>".$row['Name']."</option>";
      echo "</select>";

        $InputName = addslashes($_GET['InputName']);
      $result=mysql_query("select * from $dbTable3 where Name = '$InputName'", $link);
      // get data from db etc..
         echo "fault";
end code
  • 3
  • 3
1 Solution
This sort of thing is usually done with JavaScript... of course if your data is too big for that to be feasible, then you should use JavaScript to update the contents of a hidden IFRAME...
If the user selects a name from the list within the browser, how can you possibly get that data without going to the browser?  I'm confused.  Why do you have this requirement?

Typically in such a situation I would use Javscript's onChange to submit the data and reload the page with the new data passed along to PHP so it can handle the query and output the proper HTML.
Actually I just thought of a somewhat kludgy way.  The onChange, instead of submitting the data and having PHP reload the page with new info, could trigger a Javscript function.  Within that Javascript function you could already have a switch statement with all the corresponding data that you want outputted to the text field.  If the argument matches a case, that text is returned and displayed in your text box.  This solution is only feasible with small amounts of data though.  You don't want to have a gigantic Javascript function containing all your data if at all possible.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

which is what i suggested in the first place...
the difficulties can be smoothed however by using a hidden iframe...
with this solution the javascript doesn't load the list, it loads the iframe which contains the list.  after it's done loading then the javascript repopulates the dropdown
Haven't had the chance to use iframe before, but wouldn't it be safer to use "object" instead, since it's part of the 4.0 standard?  Plus, wouldn't using iframe to store the data be the same as coding it directly into the Javascript function as far as the amount of data that needs to be delivered before the page loads?  How about some sample code or pseudocode to demonstrate how it would be beneficial?

Either way, I think your solution should work.
with the iframe solution, you change the src as you change your text entry...

<INPUT Type="TEXT" OnChange="GetMyOptions" id="mytext" name="mytext">
<SELECT name="myselect">

<SCRIPT Language="JavaScript">
myframe.src = "www.mypage.com/myopts.php?" + encode(document.getElementById("mytext").text);

  function TwoBoxMove(a,b,c)
    //Andrew Komasinski 2004-10-25 This will move the items from one box to the other
           if (c == '>>') {
               var from = document.getElementById(a);
              var to = document.getElementById(b);
             } else
               var from = document.getElementById(b);
              var to = document.getElementById(a);
             while (from.selectedIndex > -1)
              var lastoption = new Option();
          lastoption.text = from.options[from.selectedIndex].text;
          lastoption.value = from.options[from.selectedIndex].value;
              to.options[to.length] = lastoption;
              from.options[from.selectedIndex] = null;

function reloadQ()



where shh is the name of the one being loaded in the iframe and has all of the options set to selected

(I use this code for some other stuff, edit it to fit your requirements exactly)
dwaxAuthor Commented:
Thanks guys,

The reason why i the info not from the browser, is because i  have wuite a heavy
flashmovie on the same page. With every form submit, the movie loads again...

One possible solution, not very neat is put it into frames...

The other one is using an iframe as you suggested. I will look into that a.s.ap.

thanks for your replies!


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now