Re: retrieve multiple select

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:
>>>> <select name="($categoriesIN).'[]'" multiple>
>>>> <OPTION>Choose Categories...</option>
>>>> <OPTION VALUE="1">History
>>>> <OPTION VALUE="2">Temples
>>>> <OPTION VALUE="3">Pharaohs and Queens
>>>> <OPTION VALUE="4">Cleopatra
>>>> <OPTION VALUE="5">Mummies
>>>> </SELECT>
>>>> for ($i = 0; $i < count($_POST['categoriesIN']); $i++)
>>>> echo $categoriesIN[$i];
>>>>
>>>> OR SHOULD IT BE: <select name="$categoriesIN[]" multiple size="5">
>>>>
>>>> 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...:
>>>
>>> <select name="categoriesIN[]" multiple size="5">
>>> <option>Choose Categories...</option>
>>> <option value="1">History
>>> <option value="2">Temples
>>> <option value="3">Pharaohs and Queens
>>> <option value="4">Cleopatra
>>> <option value="5">Mummies
>>> </select>
>>>
>>> if(!empty($_POST['categoriesIN'])){
>>> foreach( $_POST['categoriesIN'] as $key => $value)
>>> {
>>> echo "key = $key and value = $value<br>";
>>> }
>>> }
>>>
>>> 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 '<option value="' . $row['id'] .'">' . $row['category'] .
'</option>';
}

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux