Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.