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
getting most records by count
Code: [Select]<?php
$connect = mysql_connect("localhost","dam
Beginner question regarding Array's
Hi everyone, the page im working on has an array of variable at the top...
Code: $define_li
Odd or Even
Inside of a while loop I need to echo several rows of info...easy enough.
In the loop (for th
Pre-Fill out a PHP form...??
This is for work actually (geek squad). We have to fill out this online php form at work over and ov
random generation
hi
i need help with generating this
numbers from 1-12
i want to generate in ran
how to populate a drop down box
Hi buddies!
PROCEDURE DOWNLOAD_REPORT_FORM (report_name varchar)
is
begin
DOWNLO
How to restrict the display of report variants
Hello All,
I want t know how to restrict the display of report variants.
I mean, whe
need help with date function
i have following form for date
Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Best way to read this text file.
Hi.I am planning to make a small application in C# to convert the players from Football manager 2010
Changes to hosting company's server has affected web contact form
I started a thread a couple of months ago about the contact forms on my client's website. Basically