[thelist] mySQL- how to test if table contains data

BT Bigpant bigpant at btinternet.com
Wed Feb 6 04:08:00 CST 2002


Sorry, that should have been

$sql = "SELECT date FROM $database.$timetable WHERE Truckip like '$truckip'
AND TIME<=$timeto AND TIME>=$timefrom GROUP BY TIME ORDER BY TIME;";

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of BT Bigpant
Sent: 06 February 2002 10:10
To: thelist at lists.evolt.org
Subject: RE: [thelist] mySQL- how to test if table contains data


Off the top of my head, just retrieve the explicit dates, and you can then
grab data for each date you wish.

$sql = "SELECT date FROM $database.$timetable WHERE Truckip like '$truckip'
AND TIME<=$timeto AND TIME>=$timefrom GROUP BY date ORDER BY date;";

The above would select every used date in each month, in date order. You
would then loop through each date as before. The difference is you haven't
loaded the entire data set, just a recordset with a single line containing
each date.

HTH
Phil Parker

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Richard Bennett
Sent: 06 February 2002 09:33
To: thelist at lists.evolt.org
Subject: [thelist] mySQL- how to test if table contains data


Hi,
I am a mySQL beginner, doing someone else's work right now.

What I have is a table that stores (lots of) data per date.
I want to query the database, to know which days have data in them, at the
moment I load all the data for one month, and loop through it to see which
dates are in use - very inefficient of course.
How can I best query the database to know if a date is in use, without
extracting all the data at the same time?

I'm using Perl/mySQL
the current SQL is:

$sql="SELECT * FROM $database.$timetable WHERE Truckip like '$truckip' and
TIME<=$timeto AND TIME>=$timefrom order by TIME";

Where $timeto and $timefrom cover a 1 month segment.

Any ideas?

Richard.


--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !

--
For unsubscribe and other options, including
the Tip Harvester and archive of thelist go to:
http://lists.evolt.org Workers of the Web, evolt !



More information about the thelist mailing list