[thelist] PHP/MySQL get unique rows from the table

Matt Warden mwarden at gmail.com
Mon Jul 25 14:33:36 CDT 2005

Hash: SHA1

Hi Nan,

> I only want to show each date once. I googled for this, but am not sure how
> to word it, I used things like --------select unique row----------------but
> didn't get an answer to this question. From what I found, this might involve
> a subquery, but I have never used one and didn't understand the example. Can

A subquery isn't what you want. In fact, if you're using a ratehr old
version of MySQL, it doesn't even support subqueries.

Try this:

select distinct date(start_date)
from yourtable

You probably want to mess with the formatting of the date (for that,
see the date_format function), but this will give you the data you want.

when debugging code by using echo statements, include the line number
> and document, such as:
> echo $foo." on line 1355 of class_events.php";
> This will help you remember where you put it.

PHP has a magic constant called __LINE__ for this purpose (that way
you dont have to keep updating your echo's when you add code anywhere
above it). See

So, your tip would change to:
echo $foo ." on line ". __LINE__ ." of ". __FILE__;

or, better yet:

function debug($str, $line, $file)
	echo $str . ' on line '. $line .' of '. $file .'<br />';
debug($foo, __LINE__, __FILE__);

Luckily, PHP5 has full stack tracing and exception handling, so this
kind of thing won't be needed.

- --
Matt Warden
Miami University
Oxford, OH, USA

This email proudly and graciously contributes to entropy.
Version: GnuPG v1.2.4 (GNU/Linux)


More information about the thelist mailing list