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

Page Reload
I am having issues getting a page to reload after I submit data to a database. This form should inp

Help with PHP Calendar code...
Hello, I'm new to this forum and I'm glad I found it.
I wrote this code for a PHP calendar as an

Uploading files/images via forms
Hey all, I am building a database for work that will contain some minor data on plant species along

Set Categories
I am creating a submission form for somebody to come in and submit products. These products are sep

Help: problem with Headers to download PDF file
Hi,

I'm trying to implement a script where when a user clicks a link he gets a PDF file to op

quotes changing
hi all

in my content

opening quotes " changes to “

close qu

Find occurences of unicode characters in string
I need to prohibit filenames with everything but English characters and numbers but regexp and strin

How to give the privillege for triggers?
Hi,

How to give the privillage for triggers to particular user?

Please let me

tell csv import script to ignore blank rows?
Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the e

Clean URLs
Hi I was wandering if anyone has ever implemented URLs on their PHP run website using URLS like wiki

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