You are here: why does mysql COUNT return 1 when there are no results? « All PHP « IT news, forums, messages
why does mysql COUNT return 1 when there are no results?

Posted by davek on 10/17/06 13:02

I have a diary page listing social events in a table (stored in a mysql
db). If there are no current listings, I want to display a message
rather than an empty table.

This is the code I'm using:
**********
$query = @mysql_query('SELECT COUNT(*) FROM socials');
$count = @mysql_num_rows($query);

if ($count<1) {
echo ('<p>There are no forthcoming social events.</p>');
} else {
//show social events
}
**********

Unfortunately, this returns 1 when there are no results. It also
returns 1 when there is one result.

I'm probably being really dense and missing something obvious, but is
there a way to make it return 0 when there are no results? Or is there
a better approach to this task?

Any help much appreciated,

d.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация