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

iterating through an array and escape each value independently.
I have a set up where the variable being escaped is an array and it needs to be iterated and escaped

Batch Session SM35 stuck in status 'in Background
Hi Experts,

I am facing a problem with Batch Input session SM35.

The batch se

Question about the upload of large files
Hi there,

I have a question about the upload of large files, like videos (files generally abo

Does design fit in FPGA ?
Hi all,

I've made a large HCC-Design. Because of the program-size the compile process with th

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

Scheduler problems related to execution of a single BLT by many schedules
Hello all,

We are running several MII instances in a distibuted architecture using a sing

How do I send data using an html link
Hi

If I have
<a href="main_file.php">

How do I send data t

breaking a text file into paragraphs based on strings
I have a text file of email addresses that is all squished together. It looks like this:

abc

Sending CC Info by email
I am a little bit less knowledgable in the security area as most developers and I know I have a lot

Combining refCursors and Summing
Given the following DDL:

CREATE TABLE FOODSALESTEST ("WEEKNBR" NUMBER, "ST

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