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
302 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
2 Comments
 
LVL 77

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now