Jump to content

Making a Dynamic <select>


2tonejoe

Recommended Posts

I am currently using the Chained Menu from dynamic drive http://dynamicdrive.com/dynamicindex1/chainedmenu/index.htm and I am running a python script via cron to generate the required config.js file. It works, except when I go to pass the selected item to the form processor on the next page using php. I get nothing. Rather than trying troubleshoot the defunct javascript I was wondering if I could generate the same type of thing with php and pass the "value="'s off to another script.

 

Essentially I have a mysql table with records like:

Name(str)       Group(str)       SubGroup1(str)       SubGroup2(str)       Members(int)

The SubGroup's go up to 10, but i think you guys get the idea. I would like to have four html <selects> populated with the above data from the database. How can I do this?? Also, the Members field is a number 0-4 and I would like to populate that last <select> with x amount of options 1-x...

Link to comment
Share on other sites

This is what I do, I'm sure you can modify for your needs

 

$query3 = "SELECT * FROM users_referral WHERE `active` = 1";
$result3 = mysql_query($query3) or die ("Error in query: $query3. " . mysql_error());
if (mysql_num_rows ($result3) > 0){
	while ($row3 = mysql_fetch_object ($result3)) {
	?>
	<option value=<?php echo $row3->id; ?>><?php echo $row3->name; ?></option>
	<?php
	$referralarray[$row3->id]=$row3->name;
	}
}
else {
?>
	<option value="None">None</option>
	<?php
	$came_from = "Not Available";
}				
?>
              </select>

Link to comment
Share on other sites

My users_referral table holds something like:

 

id    name    active

1    Google    1

2    Yahoo    1

 

So what I do is query this table, load them up in an Object so my $row array points to each column.

 

I then populate the options for every entry in my table.

 

If there are no choices, I return the Not Available so at least it wont error out or be blank if the DB is down.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.