Jump to content

[SOLVED] select info using record set ad date


VHS

Recommended Posts

I am attempting to make a simple classifieds page.

 

I need to create a record set to be used to display info using PHP & MySQL from a table where the current date is greater then the end date in the table and less then the start date.

-table structure

    classified

startdate_cla

enddate_cla

description_cla

 

i.e. Display ALL form table classified where startdate_cla is less then the current date AND enddate_cla is greater than the current date. This should return everything from the table classified where the curent date is equal to or between the start date & end date.

 

Here is my code, can anyone suggest how to make this work. I would appreciate it

 

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

$coldate_rsClassified = "-1";

if (isset($today)) {

  $coldate_rsClassified = (get_magic_quotes_gpc()) ? $today : addslashes($today);

}

mysql_select_db($database_connCMS, $connCMS);

$query_rsClassified = sprintf("SELECT * FROM classified_ads WHERE enddate_cla > %s ORDER BY ID_cla DESC", $coldate_rsClassified);

$rsClassified = mysql_query($query_rsClassified, $connCMS) or die(mysql_error());

$row_rsClassified = mysql_fetch_assoc($rsClassified);

$totalRows_rsClassified = mysql_num_rows($rsClassified);

 

 

Link to comment
Share on other sites

What happens when you try to run that piece of code?

 

Oh, this:

 

$query_rsClassified = sprintf("SELECT * FROM classified_ads WHERE enddate_cla > %s ORDER BY ID_cla DESC", $coldate_rsClassified);

 

could be replaced with:

 

$query_rsClassified = "\"SELECT * FROM classified_ads WHERE enddate_cla > $coldate_rsClassified ORDER BY ID_cla DESC\"";

Link to comment
Share on other sites

This brings back everything in the table regardless of the end date

Then there is probably something wrong with other parts of the code.

 

Try to print the query before actually querying - see if it is what was supposed to be, it might shed some light on what is the problem.

Link to comment
Share on other sites

Ureka!!

 

$query_rsClassified = sprintf("SELECT * FROM classified_ads WHERE enddate_cla >= '$today' AND startdate_cla <= '$today');

 

This works perfectly only returning the the data that has a start date equal to or less then the current date AND having an end date equal to or greater than the current date.

 

Thanks a bunch for pointing me in the right direction...

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.