Jump to content

Help with a search clause...


DBookatay

Recommended Posts

I have a search page, that pulls data from my dB based on several criteria, and I want to add  a new criteria: status = "New".

"New" meaning I have a field named "submitted" that when a user submits a form it uses "NOW()" and saves it as timestamp: "2007-03-19 19:22:21," I want "New" to pull all the forms submitted within the last 7 days, but I cant get my script to work correctly. Here is what I have:

   $where[] = "submitted <= '" . date('Y-m-d', strtotime('-7 days')) . "'";

   $query = "SELECT * FROM $table $where ORDER BY $order";
   $result = mysql_query($query) or die(mysql_error()); if($result) {
   $numrows = mysql_num_rows($result); 
   while($row = mysql_fetch_array($result)){

   }

 

All of my other "$where[]" work correctly, so the only problem I have is determining what the 7 days are

"submitted <= '" . date('Y-m-d', strtotime('-7 days')) . "'";

 

Does anyone have any suggestions?

 

Link to comment
Share on other sites

mysql dates are a different format

<?php
$mysql_7daysago = date("Y-m-d G:i:s", strtotime("-7 Days"));
?>

proper syntax for mysql 7 days ago date.

 

So how do I write my line? :

$where[] = "submitted $mysql_7daysago = date("Y-m-d G:i:s", strtotime("-7 Days"));";

 

Link to comment
Share on other sites

   $mysql_7daysago = date("Y-m-d G:i:s", strtotime("-7 Days"));

   if($_GET['status'] == "New") {
      $where[] = "submitted <= $mysql_7daysago";
   } else {
      $where[] = "status = '{$_GET['status']}'";
   }

 

Error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== 2008-01-17 20:37:38 and status = 'New' ORDER BY submitted DESC, ap_nmL ASC, a' at line 1"

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.