Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
Dawg
RavenNuke(tm) Development Team



Joined: Nov 07, 2003
Posts: 928

PostPosted: Tue Aug 23, 2005 5:31 am Reply with quote

Greetings All,

I am pulling data from a database.....and what I would like to do is if the select statement comes back with no data....I would like to run another query so that is never comes back with no data.

My script runs....
[php]SELECT Time, Height FROM {$_POST['Station']} WHERE Date='$month/$day/$year'[/php]

If this comes back with no data...I would like it to do this...
[php]"SELECT Time, Height FROM {$_POST['Station']} where date = DATE_FORMAT(CURRENT_DATE(), '%c/%d/%Y')";[/php]

So it pulls the data from the current day.

How do I do that?

Thank You for your time!!

Dawg
 
View user's profile Send private message
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6437

PostPosted: Tue Aug 23, 2005 5:57 am Reply with quote

Would this work?
Code:


SELECT Time, Height FROM {$_POST['Station']} WHERE Date='$month/$day/$year or DATE_FORMAT(CURRENT_DATE(), '%c/%d/%Y')

_________________
I search, therefore I exist...
Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
Dawg







PostPosted: Wed Aug 24, 2005 7:11 am Reply with quote

That did not work along with about 500 other things I have tried so lets talk about what I am trying to do overall and see if I am going down the right path.

I have a form that generates an graph. This graph is saved in a cache file. HEre is the problem. Until they hit the submit button.....there is no data to pass to the rest of the script....to create the image...save the image....display the image.

I have varibles in the query that when you first go to the page come back as errors.....because you have not given it any data to fill the varibles.

How do I get around this?

How do I feed this script "Default" values IF the query comes up empty or IF the query has not run?

Thank You for your imput!

Dawg
 
kguske







PostPosted: Wed Aug 24, 2005 8:57 am Reply with quote

You could load defaults if the number of records returned in the query is zero. How to determine the number of records depends on the database you're using (MySQL, in this instance) and the access technique.

For standard MySQL, use the mysql_num_rows() function. e.g.
Code:
$rows = mysql_num_rows($result);

if ($rows == 0) {
..load defaults
}
 
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Thu Aug 25, 2005 4:02 am Reply with quote

Try this
Code:
SELECT Time, Height FROM {$_POST['Station']} 

WHERE IF (Date='$month/$day/$year',Date='$month/$day/$year',date = DATE_FORMAT(CURRENT_DATE(), '%c/%d/%Y'));

I haven't tested it but it looks syntactically correct. For more information on MySQL Control Flow Functions, see http://dev.mysql.com/doc/mysql/en/control-flow-functions.html
 
View user's profile Send private message
Raven







PostPosted: Tue Aug 30, 2005 8:19 pm Reply with quote

Hey Dawg, did this work or not?
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©