Solved

Date in MySQL and PHP the best way to accomplish

Posted on 2007-04-04
6
257 Views
Last Modified: 2013-12-12
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
Comment
Question by:bprof2007
  • 3
  • 2
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18851990
table (number (int), task (varchar 80) `date` (date)).


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

Accepted Solution

by:
glcummins earned 250 total points
ID: 18852007
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
 
LVL 1

Author Comment

by:bprof2007
ID: 18852155
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:bprof2007
ID: 18852422
The question is now 500 points worth after adding the last question.

Thanks,
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 18852461
>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
 
LVL 1

Author Comment

by:bprof2007
ID: 18852667
Thanks angellll, worked fine.

Thank you guys a lot for your help!
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now