LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Dynamically select data from MySQL tables (https://www.linuxquestions.org/questions/programming-9/dynamically-select-data-from-mysql-tables-420114/)

tangle 02-27-2006 02:21 PM

Dynamically select data from MySQL tables
 
I wrote a webpage in PHP that allows a user to select a customer from a drop down list that queries a MySQL table. It works fine, but the list of customers has groan and it is a pain to scroll through the list.

I would like to make it so when the user starts to type the name of the customers, the selection in the drop down box narrows. So if Mi is typed, names that start with Mi are the only ones dispalyed.

Can someone direct me to an artical or how to on how to do this? I searched the web and didn't find anything. May be my terminology is not right. Thanks

michaelk 02-27-2006 03:58 PM

It already exists in IE and firefox. Typing mi as in your example will jump down the list but not narrow the selection. I am not sure about other browsers. Since PHP is server based so I do not think it possible.

tangle 02-27-2006 10:29 PM

It must be my script. I can hit the first letter and it will drop down, but will not go any further. It will only recognize the first letter.

My code looks like this:
Code:

  echo "<tr><td width='25%'>";
  echo "<font size=4>Customer Name: </font></td>";
  echo "<td align='left'>";
  $query = "SELECT CustName FROM CustName";
  $result = mysql_query($query);
  if(mysql_num_rows($result))
    {
      echo "<select name=cname>";
      while($row = mysql_fetch_row($result))
        {
          print("<option value=\"$row[0]\">$row[0]</option>");
          echo "<br>";
        }
    }
  else
    {
      print("<option value=\"\">No users created yet</option>");
    }
  echo "</td></tr>";

It will show all data in the CustName in a drop down list. I can not type in any characters. I guess I'll look around on dynamic drop down lists. Thanks

airswit 02-28-2006 01:04 AM

i think you are going to want to look into javascript for this. you can create the javascript array with php, then with the onchange event of the input, you can alter the showing list of options. could be a pretty neat little feature.

ps, it is grown, not groan ;-)

tangle 02-28-2006 07:11 AM

Thanks for the info. I'll start looking a java scripts today.

Quote:

Originally Posted by airswit
ps, it is grown, not groan ;-)

Didn't see that. That is what I get for typing things in a hurry. That is why I always went over my college papers 5 or 6 times. lol

michaelk 02-28-2006 04:01 PM

I retract my statement Firefox does but IE does not. java is what you want.

tangle 02-28-2006 05:48 PM

I am going to buy a Java Script book this weekend. Thanks for the replies.


All times are GMT -5. The time now is 03:00 AM.