• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Date in MySQL and PHP the best way to accomplish

Hi,

I have this table (number (int), task (varchar 80) date (date)).

What I want is the ability to search for a task in a specific date, or between two dates.

I don't know if the table structure that I have created is correct or not.  Or the best way to accomplish this task?

I tried running this query in PHP

$query = "SELECT task FROM taskmngr WHERE date between '2002-08-06' and '2007-04-30'";

But I got this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\location\all.php on line 14
No data to display!

Here is line 14:

$numrows = mysql_num_rows($result);

Could someone please help me?

Thanks!
0
bprof2007
Asked:
bprof2007
  • 3
  • 2
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
table (number (int), task (varchar 80) `date` (date)).


$query = "SELECT task FROM taskmngr WHERE `date` between '2002-08-06' and '2007-04-30'";
0
 
glcumminsCommented:
Add an error reporting piece to your mysql_query line:

$result = mysql_query($query) or die("Failed while performing the following query: $query<br />MySQL error: " . mysql_error());

Note that this line must come after you create your query, and before you try to use mysql_num_rows():

<?php
 $query = "SELECT task FROM taskmngr WHERE date between '2002-08-06' and '2007-04-30'";
 $result = mysql_query($query) or die("Failed while performing the following query: $query<br />MySQL error: " . mysql_error());
 $numrows = mysql_num_rows($result);
?>
0
 
bprof2007Author Commented:
Thanks angellll, I'm sorry I didn't understand what difference `date` will make.

Thanks glcummins, your statement helped me detect the error, which was table name error (date_ not date)

Can I limit the display result through the query itself? i.e. the results were over 20 tasks, I only want to display 10 tasks-oldest tasks-?

Is there a way to do that? If not, what is the other way to do it?

Thanks for all your help guys.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bprof2007Author Commented:
The question is now 500 points worth after adding the last question.

Thanks,
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>Thanks angellll, I'm sorry I didn't understand what difference `date` will make.
date is a reserved keyword, so a column or a table with that names needs to be escaped. in Mysql, that is with backticks `


>Can I limit the display result through the query itself? i.e. the results were over 20 tasks, I only want to display 10 tasks-oldest tasks-?


 $query = "SELECT task FROM taskmngr WHERE date between '2002-08-06' and '2007-04-30' ORDER BY date ASC LIMIT 10";
0
 
bprof2007Author Commented:
Thanks angellll, worked fine.

Thank you guys a lot for your help!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now