0

Really I am a PHP beginner, I am working on this code and I need help, kinda stuck.
I have a database with 3 fields(id, date and venue). This is simply what I want to do;
I want my script to go into the database fetch the date and compare it with a declared date(todays date) and if both days are equal, it should echo out the venue that corresponds to the date taken from Mysql.

4
Contributors
11
Replies
16
Views
7 Years
Discussion Span
Last Post by aMOEBa
Featured Replies
  • Hi First you must have a valid date field in your table structure. [code] SELECT venue FROM tablename WHERE date_column = curdate() [/code] Read More

  • 1

    This should work: [code] $query = "Select venue from programOutline where `date` = '$curDate'"; [/code] If you're only interested in today, this works too: [code] $query = "Select venue from programOutline where `date` = CURDATE()"; [/code] Read More

1

Hi

First you must have a valid date field in your table structure.

SELECT venue FROM tablename WHERE date_column = curdate()
Votes + Comments
He is great.
0

I already tried the code below and it didn't work.

// DB info here
$curDate = date("Y-m-d");
$query = "Select venue from programOutline where date = $curDate";
$result = mysql_query($query);   
    while ($row = mysql_fetch_array($result)){
        echo "Today's program is at " .$row['venue'];
    }

Anyway thanks for replying so quick.

Edited by aMOEBa: n/a

-1

In what form is the date stored, as a date object or in some text form, comparing DMY d - m y y-MD makes a lot of difference, it may be impoosible to match different date formats

edit, impoosible ?? ha ha

Edited by almostbob: n/a

0

As far as I know, my variable $curDate corresponds to that of mysql. I am using the DATE data type in mysql which is of format YYYY-mm-dd. When I even convert it to time with the strtotime() function, it still doesn't work.
ie strtotime($curDate) == strtotime($row doesn't work.

1

This should work:

$query = "Select venue from programOutline where `date` = '$curDate'";

If you're only interested in today, this works too:

$query = "Select venue from programOutline where `date` = CURDATE()";
0

Thanks to all of u guys for helping me out. @pritaeas, thanks for the code, it worked.

0

Yeah I know I closed this thread but something came up, I am now able to compare both dates but I want to evaluate it so that if there is no activity for the day, I will be able to echo some kinda msg. I am finding it difficult to construct my conditional statement. Thanx

0

just a thought not verified code

// DB info here
$curDate = date("Y-m-d");
$query = "Select venue from programOutline where date = $curDate";
$result = mysql_query($query);   
 if(!$result) {echo 'No program today';}
 while ($row = mysql_fetch_array($result)){ echo "Today's program is at " .$row ['venue']; }
0

Thanks, anyway, I got around that and I ended up with this,

<?php
if($row = mysql_fetch_array($result)){
do{
echo $row['venue'];
}while($row = mysql_fetch_array($result));
}
else{
echo "No Available Program";
}
//I hope this helps someone

?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.