PHP/MySQL Query Problem!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
monkeymafia
Forum Commoner
Posts: 31
Joined: Mon Oct 08, 2007 3:08 pm

PHP/MySQL Query Problem!

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP/MySQL Query Problem!

Post by Zoxive »

Code: Select all

if(!$result)
  die('Query Failed...<br>' . mysql_error());
monkeymafia
Forum Commoner
Posts: 31
Joined: Mon Oct 08, 2007 3:08 pm

Post 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?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

The values QUARTER and WEEK are available beginning with MySQL 5.0.0.
There are 10 types of people in this world, those who understand binary and those who don't
monkeymafia
Forum Commoner
Posts: 31
Joined: Mon Oct 08, 2007 3:08 pm

Post by monkeymafia »

arghh!

so is there no way to execute a similiar query using version 4?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

:lol:

1 week = ? days
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Also, you may find YEARWEEK() useful.
There are 10 types of people in this world, those who understand binary and those who don't
monkeymafia
Forum Commoner
Posts: 31
Joined: Mon Oct 08, 2007 3:08 pm

Post by monkeymafia »

thanks for the replies.
Post Reply