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
Help with echo()
I'm having some problems with this code:
Code: echo '
<A HREF="jav
EU VAT Package 2010
Does any one know whether SAP will be developing new reporting functionality due the new VAT rules t
Setting a default timezone?
I have read about how to change the timezone in PHPMYADMIN, but it changes back, it doesn't STAY the
Company Code for Vendors created through Business Partners
Hi, experts!
I'm trying to set up the integration between Business Partner (BP) and Vendo
this code is not working????
it says this error.. Warning: Division by zero in ..
the variables are correct, so why is th
undefined offset help
Hi All,
I kept getting undefined offset PHP notice for a simple for loop. For eg
$va = arr
understanding functions and classes
Code: [Select]
class person {
var $name = "Jimmy Goe";
function get_nam
WORDPRESS - Multiple Loops Only Going to One Post?
I have various pages with multiple loops and i need them to be individual to all other categories.
filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h
WELCOME SCREEN
first of all let me tell you what does my script do,
it´s a very simple query to show a e