Solved

How to do a loop to insert each value in an array to a new row in a table

Posted on 2013-02-04
2
306 Views
Last Modified: 2013-02-05
I have an array of datetimes that is within another array ($data):

Looks like:
$data[StartDates]

How can I insert each of the dates within StartDates into a table, 1 date per row?

Something like:

foreach ($data[StartDates] as $startdate) {
$query = "INSERT INTO contest_dates (contestdate) VALUES ($startdate) ";
$result = mysql_query($query) or die(mysql_error());
}

*the above fails
Message: Use of undefined constant StartDates - assumed 'StartDates'

Hope I'm explaining it right.
thanks
0
Comment
Question by:tjyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 78

Accepted Solution

by:
arnold earned 500 total points
ID: 38853407
Foreach ($data as $startdate) {
Might be what you are looking for/at.
http://php.net/manual/en/control-structures.foreach.php
You do not use a single element/array cell

If the on tents of $data[startdate] is a list than it is a differenent story.
Could you post an example of the data
$data[startdate]
$#data
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 38854162
Hi, answer was:
Foreach ($data['ContestStartDate'] as $value) {

but got me pointed in the right direction.
Thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
migrating to phpbb forum from vBulletin 4.2 3 89
assigning javascript variable to php variable 8 64
Do not understand error message 3 44
Google Recaptcha 13 44
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question