Jump to content


PHP, MySql and HTML select menus

  • Please log in to reply
2 replies to this topic

#1 freddixon

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 March 2006 - 10:06 AM


I'm relatively new to HTML and PHP, but have been programming PLSQL for some years, and I am aware that this question might be simple, but if you don't know the answer...

I am trying to produce a site that has two <select type> lists on one of the pages that are populated from the database. The first list works fine but to get the second one to work I need to send the result value from the first select to the PHP script that controls the second. I don't know if this can be done easily as I realise that PHP is server based and HTML / Java is local.

Example of first select follows:

<select name="first" id="first" onChange="price_up(flag_form.first.value)">
<?php do
{ ?>
<option value="<?php echo $row_rs_first_list['Category_ID']?>"><?php echo $row_rs_first_list['Category_Type']?></option>
<?php }
while ($row_rs_first_list = mysql_fetch_assoc($rs_first_list));
$rows = mysql_num_rows($rs_first_list);
if($rows > 0)
mysql_data_seek($rs_first_list, 0);
$row_rs_first_list = mysql_fetch_assoc($rs_first_list);

The function "price_up" just displays the value of the select.

Anybody got any advice?


#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 02 March 2006 - 01:06 PM

Basically there are 3 ways

1 ) php

on selecting from first, submit the page and refresh the second menu then redisplay page

2 ) javascript

You need to create js arrays of options for each of the options in the first menu. Use js to refresh the second menu from the corresponding array. (baaSelect in my sig works like this)

3 ) xmlhttp request

see [a href=\"http://members.aol.com/barryaandrew/xmlhttp/article.html\" target=\"_blank\"]here[/a] for examples
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 freddixon

  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 06 March 2006 - 05:05 PM

Thanks for the help with the menus.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users