Jump to content

What is the difference of this query.


neo_phyte

Recommended Posts

I found hard to distinguish what is the problem with this query:

 

$today = gmdate('2007-06-27 01:42:28');
$expire = gmdate('2007-06-27 23:59:59');

$sql = "SELECT avatar_name FROM $table where avatar_group = 'Avatrian Central' AND dt_detection > '$today' AND dt_detection < '$expire' group by avatar_name";
$result1 = mysql_query($sql);
$numofrows1 = mysql_num_rows($result1);

 

it returns a correct OUPUT but when I changed something like this:

 

$today = gmdate('Y-m-d H:i:s');
$expire = gmdate('Y-m-d 23:59:59');

$sql = "SELECT avatar_name FROM $table where avatar_group = 'Avatrian Central' AND dt_detection > '$today' AND dt_detection < '$expire' group by avatar_name";
$result1 = mysql_query($sql);
$numofrows1 = mysql_num_rows($result1);

 

it seems that PHP stops working, it gives no output. Please advised.

 

Can you explain to me...

Link to comment
Share on other sites

Sorry my subject is not emphasize more.

 

No, the query is just the same with the first one... The difference is:

 

$today = gmdate('2007-06-27 02:01:16'); //this is hardcoded based from the result $today = gmdate('Y-m-d H:i:s'); echo $today;
$expire = gmdate('2007-06-27 23:59:59'); //this is hardcoded based from the result $expire = gmdate('Y-m-d 23:59:59'); echo $expire;

 

to this:

 

$today = gmdate('Y-m-d H:i:s');
$expire = gmdate('Y-m-d 23:59:59');

Link to comment
Share on other sites

If one query works and the other makes the script stop working then they can't possibly be the same.  While you might think they're the same, or expect they're the same, you will only know what the query string is if you echo it.

 

$sql = "SELECT ....."; // your query
echo $sql; // displays the query

Link to comment
Share on other sites

Here is the output from the 'identical' queries produced by those links:

 

SELECT avatar_name FROM tbl_avatar where avatar_group = 'Avatrian Central' AND dt_detection > '2007-06-27 06:52:26' AND dt_detection < '2007-06-27 23:59:59' group by avatar_name

 

 

SELECT avatar_name FROM tbl_avatar where avatar_group = 'Avatrian Central' AND dt_detection > '2007-06-27 11:35:16' AND dt_detection < '2007-06-27 23:59:59' group by avatar_name

 

As we can now all see, these are not identical queries - they have different starting times.  You need to look a little deeper into exactly how those times are produced.

Link to comment
Share on other sites

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.