Jump to content

[SOLVED] Finding greater than


timmah1

Recommended Posts

I'm trying to grab everything from the database that is equal to or greater than today's day.

I have this code

$today = date("Y-m-d");

$search = "SELECT * FROM photos WHERE weeks >= $today";
$query = mysql_query($search) or die(mysql_error());

$total = mysql_num_rows($query);

	if($total == 1) {
		while ($row = mysql_fetch_assoc($query)) 
		{	
		echo "$row[photo]";
		}
					}

 

But it don't show the one record that's in there.

The record has weeks as 2008-06-02, so it should show, but nothing shows.

 

Is this the correct way?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/108441-solved-finding-greater-than/
Share on other sites

try this..

 

$today = time();

 

$search = "SELECT * FROM photos WHERE UNIX_TIMESTAMP(weeks >= $today)";

$query = mysql_query($search) or die(mysql_error());

 

$total = mysql_num_rows($query);

 

if ($total == 0) {

while ($row = mysql_fetch_assoc($query)) {

echo $row[photo];

}

}

 

-- this hasnt been tested and it might not work but its worth a try ;)

Try

 

<?php $search = "SELECT * FROM photos WHERE weeks >= CAST('$today' AS DATE)"; ?>

 

OR if it's only going to be todays date

 

<?php $search = "SELECT * FROM photos WHERE weeks >= NOW()"; ?>

 

You could also try to use

 

<?php 

$today = date("Y-m-d");

$search = "SELECT * FROM photos WHERE weeks >= $today";
$query = mysql_query($search) or die(mysql_error());

$total = mysql_num_rows($query);

	//if($total == 1) {
		while ($row = mysql_fetch_assoc($query)) 
		{	
		echo "$row[photo]";
		}
				//	} ?>

 

to see if there are more than 1 rows being returned.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.