?
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
Medium Priority
?
309 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 79

Accepted Solution

by:
arnold earned 1500 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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