Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT from table by date NEWBIE

Status
Not open for further replies.

Zepher2

Technical User
Dec 29, 2001
25
US
I have created a table in my website database named Events. I made a date field named End_date to indicated the last date I want the row associated with that date to display on my page.
My code to perform a select of all table rows (listed below works fine. However, I have tried many ways to limit my search to rows with and end date greater than the current date. Each time, I get error messages telling mr the "Supplied argument is not a valid MySQL result resource"
My code for selecting all statements is:

$Current_date = date("dd,mm,yy");

Echo $Current_date;

$sql = "SELECT * FROM Events ";
$result = mysql_query($sql);

$color1 = "#ff6699";
$color2 = "#BFD8BC";
$row_count = 0;
$row_count1 = 0;




$num=mysql_numrows($result);


echo(&quot;Total entries $num <br>&quot;);


//Send fetch loop


While ($row = mysql_fetch_array($result)) {
$Event_date = $row['Event_date'];
$Description = $row['Description'];
$End_date = $row['End_date'];

Works;
I have tried to modify the SELECT statement to:

$sql = &quot;SELECT * FROM Events WHERE $Current_date < 'End_date' &quot;;
Returns errors

What an I doing wrong? Thanks in advance for your help.
 
It's probably this line:

$Current_date = date(&quot;dd,mm,yy&quot;);

I recommend you read up on the input for date() here:
Your format string will produce a date string of (for a date of July 24, 2003): &quot;2424,0707,0303&quot;. This is not a valid date format, particularly for passing to MySQL.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top