Jump to content


Photo

problems with select statement


  • Please log in to reply
3 replies to this topic

#1 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 16 February 2006 - 05:35 AM

Hi Guys,

I am having a brain fart and cant seem to work out how to do this....

My 2 tables;

phones_man
+-------+--------------+------+-----+---------+----------------+
| Field   | Type           | Null | Key | Default | Extra            |
+-------+--------------+------+-----+---------+----------------+
| id       | int(11)        |         | PRI | NULL    | auto_increment |
| name  | varchar(100) |      |       |            |                     |
+-------+--------------+------+-----+---------+----------------+

phones_mod
+--------+--------------+------+-----+---------+----------------+
| Field    | Type          | Null   | Key | Default | Extra            |
+--------+--------------+------+-----+---------+----------------+
| id        | int(11)        |         | PRI | NULL    | auto_increment |
| name   | varchar(100) |      |       |            |                      |
| man_id | int(100)     |         |       | 0         |                      |
+--------+--------------+------+-----+---------+----------------+


Ok, what I am trying to do is populate a drop down box using the results from phones_man and then populating the 2nd drop down box with the models that match the manufacturer selected in the first box.

Does that make sense?

The other alternative is to have 1 box list all the manufacturers and models like such;
man1_mod1
man1_mod2
man1_mod3
man2_mod1
man2_mod2

etc...

Either is fine, the first method would probably utilise a javascript auto form submit to populate the 2nd box i would think..

Either way, Advice needed. :)

Thanks very much.

Christian

edit - damn whitespace is ignored... there goes that formatting :(
mod edit: use [code=auto:0] and your whitespaces are back :)
The way to a mans stomach is through his heart.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 16 February 2006 - 07:54 PM

You'd have to use JavaScript either way, unless you're going to go the IFRAME/XMLHttpRequest route. And since that's the case, it makes sense simply to output both tables to a JS array, and then have one drop-down update the other. There are many tutorials on how to accomplish this.

From a MySQL standpoint, this is trivial, since you're getting back all the rows.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 17 February 2006 - 05:04 AM

[!--quoteo(post=346493:date=Feb 17 2006, 06:54 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Feb 17 2006, 06:54 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You'd have to use JavaScript either way, unless you're going to go the IFRAME/XMLHttpRequest route. And since that's the case, it makes sense simply to output both tables to a JS array, and then have one drop-down update the other. There are many tutorials on how to accomplish this.

From a MySQL standpoint, this is trivial, since you're getting back all the rows.
[/quote]


Awesome, thanks - I did end up using javascript but its so messy and I hate messy code.

Anyhoo, thanks again.
The way to a mans stomach is through his heart.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 17 February 2006 - 08:38 AM

Glad you got it working. Don't take this the wrong way, but if it's messy, it's usually incorrect -- you may want to find a better tutorial / source code example. Off the top of my head, you should be able to do it in under 10 lines of JS code.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users