Looping Problem


Posted on 16th Feb 2014 07:03 pm by admin

I've got a client that has a database with about 200 events at any given time. I'm trying to loop through the dates based on a form and show the title of the event if the start date of the form matches the start date of the event. My code:

Code: [Select]// dates
$start_date = "2009-10-24";
$end_date = "2009-11-20";

// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

// select database
mysql_select_db($db) or die ("Unable to access database!");

// build query
$qry = "SELECT * FROM table ORDER BY start_date asc";
$result = mysql_query($qry) or die("Error during query!");

// loop through every day from $start_date to $end_date
for ($d=strtotime($start_date);$d<=strtotime($end_date);$d+=86400)
{
echo date("Y-m-d", $d) . "
";

while ($row = mysql_fetch_array($result))
{
//echo $row[event_id] . " - ";
if (strtotime($row[start_date]) == $d)
{
echo $row[title] . "
";
}
}
echo "

";
}

I get a list of dates from the start date to the end date but the only titles I see are for the first date even though other titles should be showing. I know this isn't optimal coding - (the record count will never go beyond a few hundred) - but I'm wondering why nothing beyond the first date is outputting. Any help would be appreciated.

No comments posted yet

Your Answer:

Login to answer
75 Like 32 Dislike
Previous forums Next forums
Other forums

how to get values from $_Post with onchange="form.submit();"?
Hi, I have a form that submit to itself with a file upload field and two other hidden field values.<

Re-Order by ID Number
I have a cms set up for inputting an image, thumb, title, pdf, and eps. When input the database ass

IF STATEMENT HELP
Hi
i have created a calendar from a table:

Code: Calendar: October 2009
<table w

What's best way to get a user's Word doc converted to simple html and images?
Hi all,

I was just wondering if anybody has any experience of this.
Basically, I'm buildin

having a small php error tha deals with the 'foreach'
Last night i was working on a script for a cart and it seemed to working good, until this morning. F

Please help - should be a simple fix.. driving me nuts
Everything seemed to be working fine. I have a table, it alphabetically lists a bunch of cities and

read integers that returns a negative or prints the average
Im trying to finish this homework assignment by tommarow afternoon and I keep getting stuck.
Wr

C problem struct and string
Hi guys,

This is my first post and I'm hoping the experts here can help me solve my problem.<

error reporting
hey everyone

I have a production server in which I want error reporting but only on some page

Doubles are giving me problems
Ok so, first of all i made a double = 0.05, but when running the debugger it shows up as 0.04999. I

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash