[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Date in MySQL and PHP the best way to accomplish

Posted on 2007-04-04
6
Medium Priority
?
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 143

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 1000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 1

Author Comment

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

Thanks,
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 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