Record count

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Eiolon
Forum Newbie
Posts: 17
Joined: Tue Feb 14, 2006 1:42 pm

Record count

Post by Eiolon »

I made an even sign-up form using MySQL database. Can anyone help me with PHP code so when someone visits the page, it will check the database to see if 20 people have registered. If there has been 20 registrations, it won't show the form. If there haven't been 20 registrations it will show the form.

We are starting to migrate from ColdFusion to PHP and have to re-learn everything :(
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Code: Select all

$sql=mysql_query("SELECT DISTINCT COUNT(*) FROM users") OR DIE (mysql_error());
$num=mysql_num_rows($sql);

if ($num >=20){
echo "20 Users Registered";
}else{
show_form();
}
Just make show_form() a function (or long echo), to display the form

Happy Valentines Day!
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Code: Select all

$result=mysql_query("SELECT COUNT(*) FROM users") or die (mysql_error());
$num=mysql_result($result,0,0);
mysql_free_result($result);

if ($num >=20){
   echo "20 Users Registered";
}else{
   show_form();
}
I think your code is wrong, this should work
Post Reply