Jump to content

Combo-Boxes, Select Boxes and MySQL!


Hardbyte

Recommended Posts

Hi.

This is the short version:
Iv got a maintable and a sitetable. I want to record some details into the maintable and I currently have a combobox that lists the individual values of sitetable. I select a value and it records it into maintable - no probs.

But I now need to change this so I have like a VB listbox so I can select multiple entries from sitetable. But then need to add these values into maintable also; like: site1, site2, site3

Anyone point me in the right direction? I cant find how to have a listbox allowing me to submit a selection of values...

Thanks

Hardbyte
Link to comment
Share on other sites

listboxes, if set up correctly, will post their valus as an array. put open/close brackets directly after the 'name' part of your list item

[code]
<select name="mylist[]" size="10" multiple id="mylist">
... options here ...
</select>
[/code]

when you submit the form, $_POST['mylist'] or $_GET['mylist'] (whichever form method you use) will be arrays, with all the values you selected.
Link to comment
Share on other sites

Hi.

Thanks for your reply. Looks like I gotta learn arrays!

Iv got:

[code]

<select name="siteid[]" size="10" multiple id="siteid">
<option value="1">1
<option value="2">2
</select>

[/code]

then it submits the results, however Im not getting any results being posted now? at the other end Iv got:-

[code]
$siteid = $_REQUEST[siteid];
[/code]

but I guess this has got to be some kind of array also?

Thanks
Link to comment
Share on other sites

couple of points.

1) have you put the select listbox inside your form with a submit button?

[b]EDIT:[/b] oh - remember to close your tags (in this case, <option>). sometimes you don't HAVE to, but it's very very good practice if you want fluid, cross-browser code:

[code]
<form name="myform" id="myform" method="post">
   <select name="siteid[]" size="10" multiple id="siteid">
      <option value="1">1</option>
      <option value="2">2</option>
   </select>
   <input type="submit" name="Submit" value="Submit" />
</form>
[/code]

2) NEVER use $_REQUEST if you can help it. use $_GET or $_POST, depending on where you get the info from. try this at the very top of your page. it'll literally dump the contents of your selected values on the screen, for you to see it working:

[code]
<?php
$stuff_i_want = $_POST['siteid'];

print_r($stuff_i_want);
?>
[/code]


remember, only items tht have been selected will pass their value.
Link to comment
Share on other sites

Thank you so much for your help, Im nearly there...

When doing what you said previosuly, I get printed:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Array ( [0] => Stoke [1] => Banbury )[/quote]

What I need todo is put these values together like $sites="Stoke, Banbury" so these values are entered into the database like:

[code]$query = "INSERT INTO logs (logdate, logtime, logdesc, sites, statusid) VALUES ('$date', '$datetime', '$logdesc', '$sites', '$statusid')"; [/code]

where $sites being the values selected.

Any more help would be appreciated.

Almost there - thank you!
Link to comment
Share on other sites

[!--quoteo(post=357567:date=Mar 23 2006, 12:39 PM:name=Hardbyte)--][div class=\'quotetop\']QUOTE(Hardbyte @ Mar 23 2006, 12:39 PM) [snapback]357567[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Mark, your the ultimate guru!

Thank you so much for your quick responces and you resolved it!

Thanks again (im sure Ill be back shortly lol)

Hardbyte
[/quote]

lol not a problem, glad it worked.

ahh Stoke and Banbury...happy memories.

Cheers
Mark
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.