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

dropdown box help - open php files to textarea
Hi, I am using tinymce to edit content located in several php files. The code I attached works but i

IS Retail & Manufacturing
Hi

Can IS Retail and Manufacturing activities be done in same instance ie. in same client

losing session vars when arriving from an email link
Hi,

I've got a confirmation script made that sends an email with a link for a user to confirm

Number Format
Hi All,

I have number '000000000050085' I want to format it to 500.85 Can any one give me

Javascript or not?
How many people prefer javascript/ajax sites? How many prefer the good old fashion straight php sit

PHP Include w/If IE Condition Statement?
I was having a problem with Internet Exploder (big surprise, right?) displaying my drop down menus i

Request for tunning the below query
Hi,

Can any one help me on the below query while improving the performance,

Warning: mysql_num_rows() expects parameter 1
When i add quote at the end of this link
example:http://localhost/articlemania/category.php?cid=3

Not Loading Function Into Div
I'm not sure whether to put this under the php forum or ajax forum but because I tink it's more of a

New Search Engine problem
Hey everyone,

I have a ZIP Code Radius search engine already functional. it displays all of t

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