Q:

mySql query return if row is equal

OK I tried looking through the mySQL threads but I couldn't find what I wanted probably because I didn't know the correct terms.
Anyways I need a query to return rows that are equal to a string. This case "David" I want to show two things "comments" and "postdate". Only the date is being shown right now but no comments. Yes there is data in the comments.
Here is what I have so far:
> $query  = "SELECT * FROM sessionscomments  session = 'David'"; 
> $result = mysql_query($query);
> 
> 
> while($row = mysql_fetch_assoc($result)) {
> 
>   echo    "<div id=fav>";     
>   echo    strip_tags( "Date: {$row['postdate']}");
>   echo    "</div>";   
>   echo    "<br>";     
>   echo    strip_tags("{$row['comments']}");
>   echo    "<br>";     
>   echo    "<hr class= \"box\">";
> 
> }

and I have the date stored with CURRENT_TIMESTAMP how can I just show the day month and year?
and how can I have the last echo line NOT happen with the last run through? 
Thanks in advance.

A:

It's called a WHERE clause, and you've almost got it in your query:
SELECT comments, postdate
FROM sessioncomments
WHERE session='David'

Don't use SELECT *. It's inefficient, especially if it's a "wide" table and you're only going to use a couple fields. It's like hauling home a month's worth of groceries and then throwing it all in the trash and eating only the jellybeans and cookies.
As well, don't assume a query succeeds. At bare mininum, for developing purposes, you should always do something like this:
$result = mysql_query($sql) or die(mysql_error());
                            ^^^^^^^^^^^^^^^^^^^^^

This'll kill the script if the query fails, and tell you exactly why it failed. Otherwise your script would simply continue onwards with no (or bad) results and probably screw up later on because of this bad data.

