Re: [PHP] retrieve multiple select
PJ wrote: Well, I think 60+ checkboxes get kind of garbagy I bet it is easier to select the fields you want from 4 columns of 15 checkboxes than from a big long list of 60 in a select. But you might be right. I don't design for a living. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
PJ wrote: Michael A. Peters wrote: PJ wrote: Well, I think 60+ checkboxes get kind of garbagy I bet it is easier to select the fields you want from 4 columns of 15 checkboxes than from a big long list of 60 in a select. But you might be right. I don't design for a living. Neither do I; it's rather a question of necessity: "do or die!" :-) But I'm glad you brought this up. Only problem is, I think that the code to gather the 60+ inputs would get long and more complicated than dealing with the multiple input dropdown box. Probably a matter of personal choice. Thanks. Have not tried it with check boxes but it works with file uploads - A bunch of those all with something[] and they will all be in same post array variable. Just make sure yourvalue is unique to the checkbox, so you know which checkboxes were selected. I've not tried that, but name="something[]" works with file inputs so that they are all in same post variable as an array. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
Shawn McKenzie wrote: > PJ wrote: > >> Shawn McKenzie wrote: >> >>> PJ wrote: >>> PJ wrote: > I'm sure this has been hashed over and over on the web, only I can't > find anything that makes sense or the explanations given have been > erroneous. > This is what I am trying: > > Choose Categories... > History > Temples > Pharaohs and Queens > Cleopatra > Mummies > > for ($i = 0; $i < count($_POST['categoriesIN']); $i++) > echo $categoriesIN[$i]; > > OR SHOULD IT BE: > > BUT NEITHER WORKS. I have tried print_r, while, and other off the wall > stuff I found on the Weird Warped Web! It's unreal how much crap there > is out there... :-( > > I understood that the input from a select dropdown box was an array... > OK, so how do I retrieve the array and verify what was entered? I > suppose if I could verify, then I should be able to retrieve and > INSERT etc. > As I delve deeper into this the more I know the "horseman knew her" > ... :-) > Please elucidate, enlighten me from my erring ways ... > > Well, well, well... somehow I manged to get it right...: Choose Categories... History Temples Pharaohs and Queens Cleopatra Mummies if(!empty($_POST['categoriesIN'])){ foreach( $_POST['categoriesIN'] as $key => $value) { echo "key = $key and value = $value"; } } Now, how do I send these values to an INSERT statement? >>> Depends. What does your table(s) look like and to what fields do the >>> values go? >>> >>> I can't divine your use here, but normally with something like multiple >>> categories that are assigned to something you'll have a join table as >>> has been discussed many times recently. >>> >> Indeed, there is a join table and that's where the values will go. The >> categories table lists all the categories and the numbers in the >> multiple select box are the id for the category. >> But now that I have your attention, is there a way to select all the >> fields of the catgories table (categories.id and category) and place >> them in the multiple select box? Probably is and probably is complicated >> as hell... :-) >> > > Not a working example, but should speed you on your way: > > $result = mysql_query("SELECT id, category FROM categories"); > > while ($row = mysql_fetch_assoc($result)) { > echo '' . $row['category'] . > ''; > } > > Have you looked at a framework? CakePHP maybe? Qcodo... > Tried to use dev-php but i can't get it set up right... instructions are not clear. I may try this winlamp (i forget the exact name) but it seems like wasting a lot of time I'll certainly try CakePHP... looks interesting. Thanks for the tip; hadn't run across it in my php wanderings... -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
Michael A. Peters wrote: > PJ wrote: > >> Well, I think 60+ checkboxes get kind of garbagy > > I bet it is easier to select the fields you want from 4 columns of 15 > checkboxes than from a big long list of 60 in a select. > > But you might be right. I don't design for a living. > Neither do I; it's rather a question of necessity: "do or die!" :-) But I'm glad you brought this up. Only problem is, I think that the code to gather the 60+ inputs would get long and more complicated than dealing with the multiple input dropdown box. Probably a matter of personal choice. Thanks. -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
PJ wrote: > Shawn McKenzie wrote: >> PJ wrote: >>> PJ wrote: I'm sure this has been hashed over and over on the web, only I can't find anything that makes sense or the explanations given have been erroneous. This is what I am trying: Choose Categories... History Temples Pharaohs and Queens Cleopatra Mummies for ($i = 0; $i < count($_POST['categoriesIN']); $i++) echo $categoriesIN[$i]; OR SHOULD IT BE: BUT NEITHER WORKS. I have tried print_r, while, and other off the wall stuff I found on the Weird Warped Web! It's unreal how much crap there is out there... :-( I understood that the input from a select dropdown box was an array... OK, so how do I retrieve the array and verify what was entered? I suppose if I could verify, then I should be able to retrieve and INSERT etc. As I delve deeper into this the more I know the "horseman knew her" ... :-) Please elucidate, enlighten me from my erring ways ... >>> Well, well, well... somehow I manged to get it right...: >>> >>> >>> Choose Categories... >>> History >>> Temples >>> Pharaohs and Queens >>> Cleopatra >>> Mummies >>> >>> >>> if(!empty($_POST['categoriesIN'])){ >>> foreach( $_POST['categoriesIN'] as $key => $value) >>> { >>> echo "key = $key and value = $value"; >>> } >>> } >>> >>> Now, how do I send these values to an INSERT statement? >>> >> Depends. What does your table(s) look like and to what fields do the >> values go? >> >> I can't divine your use here, but normally with something like multiple >> categories that are assigned to something you'll have a join table as >> has been discussed many times recently. > Indeed, there is a join table and that's where the values will go. The > categories table lists all the categories and the numbers in the > multiple select box are the id for the category. > But now that I have your attention, is there a way to select all the > fields of the catgories table (categories.id and category) and place > them in the multiple select box? Probably is and probably is complicated > as hell... :-) Not a working example, but should speed you on your way: $result = mysql_query("SELECT id, category FROM categories"); while ($row = mysql_fetch_assoc($result)) { echo '' . $row['category'] . ''; } Have you looked at a framework? CakePHP maybe? Qcodo... -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
Shawn McKenzie wrote: > PJ wrote: >> PJ wrote: >>> I'm sure this has been hashed over and over on the web, only I can't >>> find anything that makes sense or the explanations given have been >>> erroneous. >>> This is what I am trying: >>> >>> Choose Categories... >>> History >>> Temples >>> Pharaohs and Queens >>> Cleopatra >>> Mummies >>> >>> for ($i = 0; $i < count($_POST['categoriesIN']); $i++) >>> echo $categoriesIN[$i]; >>> >>> OR SHOULD IT BE: >>> >>> BUT NEITHER WORKS. I have tried print_r, while, and other off the wall >>> stuff I found on the Weird Warped Web! It's unreal how much crap there >>> is out there... :-( >>> >>> I understood that the input from a select dropdown box was an array... >>> OK, so how do I retrieve the array and verify what was entered? I >>> suppose if I could verify, then I should be able to retrieve and >>> INSERT etc. >>> As I delve deeper into this the more I know the "horseman knew her" >>> ... :-) >>> Please elucidate, enlighten me from my erring ways ... >>> >> Well, well, well... somehow I manged to get it right...: >> >> >> Choose Categories... >> History >> Temples >> Pharaohs and Queens >> Cleopatra >> Mummies >> >> >> if(!empty($_POST['categoriesIN'])){ >> foreach( $_POST['categoriesIN'] as $key => $value) >> { >> echo "key = $key and value = $value"; >> } >> } >> >> Now, how do I send these values to an INSERT statement? >> > > Depends. What does your table(s) look like and to what fields do the > values go? > > I can't divine your use here, but normally with something like multiple > categories that are assigned to something you'll have a join table as > has been discussed many times recently. Indeed, there is a join table and that's where the values will go. The categories table lists all the categories and the numbers in the multiple select box are the id for the category. But now that I have your attention, is there a way to select all the fields of the catgories table (categories.id and category) and place them in the multiple select box? Probably is and probably is complicated as hell... :-) -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
Michael A. Peters wrote: > PJ wrote: >> I'm sure this has been hashed over and over on the web, only I can't >> find anything that makes sense or the explanations given have been >> erroneous. >> This is what I am trying: >> >> Choose Categories... >> History >> Temples >> Pharaohs and Queens >> Cleopatra >> Mummies >> > > Whenever something doesn't work for me I always make sure what I am > doing is valid html/xhtml > > That doesn't look valid to me - multiple="multiple" might be. > Maybe it is valid under older html. It must be. I think I got it from some ancien post and just hadn't changed it yet. But if I am permitted to p&m a little, then why the dingle-bats don't they enforce the validation. Maybe that would make everyone sit up a little and pay attention. :-) and follow the rules, so to speak. > > > But anyway, multiple selects are a bad idea because they are confusing > for users, there's no standard way with which to choose them and users > often don't know how - if you can use checkboxes instead. Well, I think 60+ checkboxes get kind of garbagy and in my use it is only the administrators who will be using this... up to now, at least. :-) > > > That being said, I think your problem is the $ and the [] > > Try > > > > Then when processing the form - $_POST['categoriesIN'] will be an > array - IE > > for ($i=0;$i do_stuff_with($_POST['categoriesIN'][$i]); > } > -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] retrieve multiple select
> -Original Message- > From: Shawn McKenzie [mailto:nos...@mckenzies.net] > Sent: Monday, March 02, 2009 3:41 PM > To: php-general@lists.php.net > Subject: Re: [PHP] retrieve multiple select > > Shawn McKenzie wrote: > > Michael A. Peters wrote: > >> PJ wrote: > >>> I'm sure this has been hashed over and over on the web, only I > can't > >>> find anything that makes sense or the explanations given have been > >>> erroneous. > >>> This is what I am trying: > >>> > >>> Choose Categories... > >>> History > >>> Temples > >>> Pharaohs and Queens > >>> Cleopatra > >>> Mummies > >>> > >> Whenever something doesn't work for me I always make sure what I am > >> doing is valid html/xhtml > >> > >> That doesn't look valid to me - multiple="multiple" might be. > >> Maybe it is valid under older html. > > > > HTML 4.01 > > > > multiple [CI] > > If set, this boolean attribute allows multiple selections. If not > > set, the SELECT element only permits single selections. > > > > However, all the options should be closed. > > Instead of: History > > Use: History > > Also, you should move the Choose Categories... out of > the select or you'll get it as an array item if someone actually > selects > it. You could I guess set it to disabled also. I believe if you just do Choose something it's pretty easy to discard an empty value if that's what they've selected. // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
Shawn McKenzie wrote: > Michael A. Peters wrote: >> PJ wrote: >>> I'm sure this has been hashed over and over on the web, only I can't >>> find anything that makes sense or the explanations given have been >>> erroneous. >>> This is what I am trying: >>> >>> Choose Categories... >>> History >>> Temples >>> Pharaohs and Queens >>> Cleopatra >>> Mummies >>> >> Whenever something doesn't work for me I always make sure what I am >> doing is valid html/xhtml >> >> That doesn't look valid to me - multiple="multiple" might be. >> Maybe it is valid under older html. > > HTML 4.01 > > multiple [CI] > If set, this boolean attribute allows multiple selections. If not > set, the SELECT element only permits single selections. > However, all the options should be closed. Instead of: History Use: History Also, you should move the Choose Categories... out of the select or you'll get it as an array item if someone actually selects it. You could I guess set it to disabled also. > >> But anyway, multiple selects are a bad idea because they are confusing >> for users, there's no standard way with which to choose them and users >> often don't know how - if you can use checkboxes instead. >> >> That being said, I think your problem is the $ and the [] >> >> Try >> >> >> >> Then when processing the form - $_POST['categoriesIN'] will be an array >> - IE >> >> for ($i=0;$i> do_stuff_with($_POST['categoriesIN'][$i]); >> } > > -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
Michael A. Peters wrote: > PJ wrote: >> I'm sure this has been hashed over and over on the web, only I can't >> find anything that makes sense or the explanations given have been >> erroneous. >> This is what I am trying: >> >> Choose Categories... >> History >> Temples >> Pharaohs and Queens >> Cleopatra >> Mummies >> > > Whenever something doesn't work for me I always make sure what I am > doing is valid html/xhtml > > That doesn't look valid to me - multiple="multiple" might be. > Maybe it is valid under older html. HTML 4.01 multiple [CI] If set, this boolean attribute allows multiple selections. If not set, the SELECT element only permits single selections. > But anyway, multiple selects are a bad idea because they are confusing > for users, there's no standard way with which to choose them and users > often don't know how - if you can use checkboxes instead. > > That being said, I think your problem is the $ and the [] > > Try > > > > Then when processing the form - $_POST['categoriesIN'] will be an array > - IE > > for ($i=0;$i do_stuff_with($_POST['categoriesIN'][$i]); > } -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
PJ wrote: > PJ wrote: >> I'm sure this has been hashed over and over on the web, only I can't >> find anything that makes sense or the explanations given have been >> erroneous. >> This is what I am trying: >> >> Choose Categories... >> History >> Temples >> Pharaohs and Queens >> Cleopatra >> Mummies >> >> for ($i = 0; $i < count($_POST['categoriesIN']); $i++) >> echo $categoriesIN[$i]; >> >> OR SHOULD IT BE: >> >> BUT NEITHER WORKS. I have tried print_r, while, and other off the wall >> stuff I found on the Weird Warped Web! It's unreal how much crap there >> is out there... :-( >> >> I understood that the input from a select dropdown box was an array... >> OK, so how do I retrieve the array and verify what was entered? I >> suppose if I could verify, then I should be able to retrieve and INSERT etc. >> As I delve deeper into this the more I know the "horseman knew her" ... :-) >> Please elucidate, enlighten me from my erring ways ... >> > Well, well, well... somehow I manged to get it right...: > > > Choose Categories... > History > Temples > Pharaohs and Queens > Cleopatra > Mummies > > > if(!empty($_POST['categoriesIN'])){ > foreach( $_POST['categoriesIN'] as $key => $value) > { > echo "key = $key and value = $value"; > } > } > > Now, how do I send these values to an INSERT statement? > Depends. What does your table(s) look like and to what fields do the values go? I can't divine your use here, but normally with something like multiple categories that are assigned to something you'll have a join table as has been discussed many times recently. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
PJ wrote: I'm sure this has been hashed over and over on the web, only I can't find anything that makes sense or the explanations given have been erroneous. This is what I am trying: Choose Categories... History Temples Pharaohs and Queens Cleopatra Mummies Whenever something doesn't work for me I always make sure what I am doing is valid html/xhtml That doesn't look valid to me - multiple="multiple" might be. Maybe it is valid under older html. But anyway, multiple selects are a bad idea because they are confusing for users, there's no standard way with which to choose them and users often don't know how - if you can use checkboxes instead. That being said, I think your problem is the $ and the [] Try Then when processing the form - $_POST['categoriesIN'] will be an array - IE for ($i=0;$ihttp://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve multiple select
PJ wrote: > I'm sure this has been hashed over and over on the web, only I can't > find anything that makes sense or the explanations given have been > erroneous. > This is what I am trying: > > Choose Categories... > History > Temples > Pharaohs and Queens > Cleopatra > Mummies > > for ($i = 0; $i < count($_POST['categoriesIN']); $i++) > echo $categoriesIN[$i]; > > OR SHOULD IT BE: > > BUT NEITHER WORKS. I have tried print_r, while, and other off the wall > stuff I found on the Weird Warped Web! It's unreal how much crap there > is out there... :-( > > I understood that the input from a select dropdown box was an array... > OK, so how do I retrieve the array and verify what was entered? I > suppose if I could verify, then I should be able to retrieve and INSERT etc. > As I delve deeper into this the more I know the "horseman knew her" ... :-) > Please elucidate, enlighten me from my erring ways ... > Well, well, well... somehow I manged to get it right...: Choose Categories... History Temples Pharaohs and Queens Cleopatra Mummies if(!empty($_POST['categoriesIN'])){ foreach( $_POST['categoriesIN'] as $key => $value) { echo "key = $key and value = $value"; } } Now, how do I send these values to an INSERT statement? -- Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php