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
get font info from a font file
hello,
Does anyone know how to get font info from a font file ... using php of course !
<
php redirecting
i wont open a new thread but i have a question about redirecting....
i wonder why my code doesnt
present value of sequence?
Hi
Please help me to find out the present value of sequence?
Thanks
animation progress while uploading files?
Hello, i have some website form to upload few files to server. i want to put some gif animation whi
Where do I put CRON code
So I've figured out alot about how to automatically run a php function. I can't figure out where to
Not adding to db
Hi, I can't figure out why it won't add the record to the database. It's just a simple form to get
php multiple action on submit
I have a form which says:
<form enctype='multipart/form-data' method='post' action='pr
help with multi-update
Now sure how to ask this really....
10g database if that matters.
I have a customer
Remote Database Access
Hey guys!!
OK, i'm used to only working with databases from the CPANEL, accessing phpMyAdmin
need help in dynamic select menu in php
hi i have created a dynamic select menu using php. i have a problem in that which is when the user s