Whats wrong with this code?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

Whats wrong with this code?

Post by virgil »

Hi,
This is driving me crazy.

How do I get multiple selected option values from a dropdown list, in a form, to insert into a table? I only seem to be able to get the first selection sent to the database. Or if I make it an array...... i.e.:

<select size="3" name="sport_type[]" multiple>
<option>baseball </option>
<option>football</option>
<option>basketball</option>
<option>soccer </option>

.......I get the just the word Array in the table column. I take this to mean that the multiple selected option values are stored, in the table column, as an array. When I use FOREACH to extract the data from the array, from the database, I still get just the word Array returned! MYSQL_FETCH_ROW does the same thing. What is wrong? Do I have to maybe nest FOREACH statements? I tried but just got an argument error.
How does it work? Actual code below:


FORM THAT SENDS DATA TO MySQL DATABASE....

<select size="3" name="date_day[]" multiple>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>




PHP RESULTS QUERY PAGE....


$query = "SELECT date_day FROM eventpost
$result = mysql_query($query);


while ($dayarray=mysql_fetch_array($result))

{
foreach ($dayarray as $day)

{
echo"<br><b>The days are </b>"."$day";
}
}


THE ACTUAL RESULTS ARE AS FOLLOWS:


The days are Array


I want it to return:

The days are 1
The days are 2
The days are 4 ...etc.


Thanks for any advice.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

virgil
Forum Commoner
Posts: 59
Joined: Thu Jun 13, 2002 11:43 pm
Location: New York, U.S.

IMPLODE!

Post by virgil »

IMPLODE!
Thats it!
:D :D :D
Thanks Vodka! eh...Volka :roll:
Last edited by virgil on Mon Jun 17, 2002 8:06 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Code: Select all

'volka' != 'vodka'
:lol:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

no, that's quite a while in the past ;)
Post Reply