Page 1 of 1

PHP/MySQL Query Problem!

Posted: Thu Nov 29, 2007 6:43 am
by monkeymafia
hi all

trying to execute a query and display items that have been updated within the past week. am pretty sure the query itself is correct but its throwing the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/kumar/public_html/Storm Broadband/datequery1.php on line 10


here is all the code:

Code: Select all

<?php

include 'dbconnect.php'; 


    $result = mysql_query('SELECT * FROM technicalproblems
        WHERE updated > DATE_SUB(NOW(), INTERVAL 1 WEEK)
		ORDER BY created DESC');
print "<h1>Items updated within past week</h1>\n";
    if (mysql_num_rows($result)) {
        print "<TABLE BORDER=\"1\"><TR STYLE=\"font-weight: bold;\"><TD>MemberID</TD><TD>First Name</TD><TD>Surname</TD><TD>Package</TD></TR>";

        while($row = mysql_fetch_assoc($result)) {
            extract($row);
            print "<TR><TD>$updated</TD><TD>$created</TD><TD>$fk_memberid2</TD><TD>$subject</TD></TR>";
        }
    
        print "</TABLE>";
    }
?>
not to sure whats going wrong. any ideas? thanks for any help

Re: PHP/MySQL Query Problem!

Posted: Thu Nov 29, 2007 7:50 am
by Zoxive

Code: Select all

if(!$result)
  die('Query Failed...<br>' . mysql_error());

Posted: Thu Nov 29, 2007 8:08 am
by monkeymafia
thanks for the reply. its stating that theres a problem with the actual query:

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 'WEEK)' at line 2

Not too sure whats wrong with the query though?

Posted: Thu Nov 29, 2007 8:34 am
by VladSun
The values QUARTER and WEEK are available beginning with MySQL 5.0.0.

Posted: Thu Nov 29, 2007 8:37 am
by monkeymafia
arghh!

so is there no way to execute a similiar query using version 4?

Posted: Thu Nov 29, 2007 9:02 am
by VladSun
:lol:

1 week = ? days

Posted: Thu Nov 29, 2007 9:10 am
by VladSun
Also, you may find YEARWEEK() useful.

Posted: Sat Dec 01, 2007 8:55 am
by monkeymafia
thanks for the replies.