This might seem like a trivial thing, but has anyone has come up with a
better way of outputting a singular vs. plural string?
For example:
// default plural label
$string = "appointmen ts";
// singular label
if (mysql_num_rows ($results) == 1) $string = "appointmen t";
print mysql_num_rows( $results) . $string;
$results always contain 1 or more records so "0 appointments" is not
applicable.
Is there a way to do this in one line (perhaps with regular expressions)
without resorting to something lame like "1 appointment(s)" ?
Again, no biggie and the above syntax is tried and true, but it's always
nice to learn a new trick now and then.
Thanks.
better way of outputting a singular vs. plural string?
For example:
// default plural label
$string = "appointmen ts";
// singular label
if (mysql_num_rows ($results) == 1) $string = "appointmen t";
print mysql_num_rows( $results) . $string;
$results always contain 1 or more records so "0 appointments" is not
applicable.
Is there a way to do this in one line (perhaps with regular expressions)
without resorting to something lame like "1 appointment(s)" ?
Again, no biggie and the above syntax is tried and true, but it's always
nice to learn a new trick now and then.
Thanks.
Comment