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

problem with GROUP BY and ORDER BY
i usually use this query to display the last 10 entries from a sql table:

Code: $query = &quo

help with variable
I've got a problem, i want to echo some images depending on the $id, however for me to get that id i

ldap connection
We are using ldap to get user information from the domain controller. It was working before. Recentl

Business Health Check
Hello

I need to create an online business health check for a client it will be multiple choi

PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see

DATEDIFF Question
First time post, and of course it is a help question.

I am using a WP plug-in to display prev

php forms and database navigatio
Hello,
I'm new to php and i'd like to post the following.
I have written code to get records f

PHP doesn't send my mail
Hi all, I found this and used it to send mail. Simple contact form with some required fields. The va

Problem with PHP code- simple contact form
I'm relativily new to PHP; I know HTML and CSS stuff but I have a problem- I have a contact form wit

private constructor
Hello,

Can we create a constructor as private? If yes, what is the use of it? If no, why can'

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