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
Last character removed
I have created a string from an array. I have inserted commas from my form values. I am trying to re
Checking if a process is running (problems including psapi.dll i think...)
Ok, so all I'm trying to do is check if a program is running...
I've found out that I nee
Hotlinking Picasa as the image folder of a website
Hi there PHP freaks, I would like to create a private album in Picasa to use it as the image folder
A little help in c#
i am doing a simple paint program using c# i want to draw with the mouse so i wrote the code of the
upload image name with extension using php
hi frds..
<input id="file1" type="file" name="file[]" &a
CODE NOT WORKING
Code: [Select]<?php
//include shared codes
include '../lib/common.php';
include
send() and recv() parameters confusion
On server Side:
int recv (Socket,Buffer, Length, Flags)
On Client Side:
int send (Soc
Inserting multiple records from single form
I've found a number of threads that deal with this issue, but I'm new to php and coding language so
upload only text files
hi guys i want to upload only text like like (pdf,note pad and ofiice files) so can any one please t
Help with Contact Form
I have this Form on an html page and the associated code on page.php (below).
I keep getting the