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
304 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.

822 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