Hardbyte Posted March 23, 2006 Share Posted March 23, 2006 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, site3Anyone point me in the right direction? I cant find how to have a listbox allowing me to submit a selection of values...ThanksHardbyte Quote Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/ Share on other sites More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/#findComment-19898 Share on other sites More sharing options...
Hardbyte Posted March 23, 2006 Author Share Posted March 23, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/#findComment-19906 Share on other sites More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/#findComment-19914 Share on other sites More sharing options...
Hardbyte Posted March 23, 2006 Author Share Posted March 23, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/#findComment-19916 Share on other sites More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 ok, just put one more line then[code]$stuff_i_want = $_POST['siteid'];$sites = implode(",", $stuff_i_want);[/code]which will string together all your values ready for inserting into your DBHope that helpsCheersMark Quote Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/#findComment-19918 Share on other sites More sharing options...
Hardbyte Posted March 23, 2006 Author Share Posted March 23, 2006 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 Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/#findComment-19920 Share on other sites More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 [!--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.CheersMark Quote Link to comment https://forums.phpfreaks.com/topic/5576-combo-boxes-select-boxes-and-mysql/#findComment-19921 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.