php - Different button colors based on database query -
i have web form allows people sign class. @ bottom of form submit button says "sign up". in php code, checking number of people have registered class. if count equal specific number, 60 registrants, want change button red , text changed "class full". how do css if can define 1 button color?
this css:
button { padding: 19px 39px 18px 39px; color: #fff; background-color: #4bc970; font-size: 18px; text-align: center; font-style: normal; border-radius: 5px; width: 100%; border: 1px solid #3ac162; border-width: 1px 1px 3px; box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset; margin-bottom: 10px; } button1 { padding: 19px 39px 18px 39px; color: #fff; background-color: #ff0000; font-size: 18px; text-align: center; font-style: normal; border-radius: 5px; width: 100%; border: 1px solid #3ac162; border-width: 1px 1px 3px; box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset; margin-bottom: 10px; }
in php code, have this:
<?php $count = mysql_query("select count(*) students;"); if ($count < 60){ echo'<button type="submit" name="signup">sign up'; }else{ echo'<button1 type="submit" name="">class full'; } ?>
i know can't use 'button1' in css, how do turns red , says class full when $count = 60?
you need fetch
, http://php.net/manual/en/function.mysql-fetch-row.php, result of query. have value.
note using deprecated/removed driver well.
warning extension deprecated in php 5.5.0, , removed in php 7.0.0. instead, mysqli or pdo_mysql extension should used.
so code be:
<?php $count = mysql_query("select count(*) students;"); $array = mysql_fetch_row($count); if ($array[0] < 60){ echo'<button type="submit" name="signup">sign up'; }else{ echo'<button1 type="submit" name="">class full'; } ?>
you should use id
s or class
s assign css properties.
...or id
approach:
<?php $count = mysql_query("select count(*) students;"); $array = mysql_fetch_row($count); if ($array[0] < 60){ echo'<button type="submit" id="aval" name="signup">sign up'; }else{ echo'<button1 type="submit" name="" id="full">class full'; } ?>
then css assignments become:
#aval {
and
#full {
or replace #
.
if choose use class
. if can have multiple occurrences use classes.
Comments
Post a Comment