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
Why use OOP?
Can someone explain to me why I should use OOP instead of procedure based code.
Im building a
Session
I am having a little trouble with a session. Not sure if it is my browser or what. I know I do not
add to sql result
ok see rite now my sites hit counter is counted from the mysql visitor log i need to clear it aft
Must-Know Topics of PHP
Can you guys list the must-know topics of PHP. I am still a learner and I am trying to cover most of
Auto-populating dropdowns and multiple forms.
Here's what I have so far:
First drop down = select a state (works)
This populates the sec
Aris, Netweaver BPM, Visual composer and X'app
Dear Experts,
Whats the relationship between the following components: Aris, Netweaver BP
help removing unwanted graphic
How do I remove the small elongated rectangular shape between the "Latest post" and "
Add "width" check when upload
Hi!
Can someone add a function that is checking if picture witdh is bigger then 800px whwn up
Problem with variable declaration in switch statement
Hello, I am having some trouble assigning a value to a variable inside a switch statement. What I a
Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there