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
32
Other forums
limit string by words??
hello all,
I was wonder if there is a function to limit a string by the number of words inste
Paypal
Hi all,
I have an advanced basic knowledge of php
I want to try something new for a s
Variable uses and placement
I'm new to PL/SQL and am trying to learn about variable valid uses/placement (any pointers to any do
How many users online in the last 24-hours using time()?
I'm fairly new to PHP. I have a MySQL table called 'users' and a field called 'loggedin' which is in
Members Only
Hi all, for my website i have a members area only which on members can veiw, but at the moment anyon
am I using this for loop correctly
Dear buddies!
Right now I am generating a report with some details for all the dealers.
Add User script "Could not execute query"
This should be an easy script but I can't get it to run. Can someone please help me?
<
Had a simple form script that suddenly stopped working
It was made about a year ago and had been working fine. Last time it was known to work for sure was
PHP Multiples of 2, Show posts...not working (wordpress)
I have been using this code to show div.example with 6 li columns inside it, each li is a post with
Setting condidtions for an input box
Hi all,
I would like to set a condition in a txt box that says the number a user enters has t