Boolean with PHP
Hello,
I have a bunch of tinyint fields in a mysql database that I need to show using PHP. At the moment I am doing something like this:
if ($row['PAYPAL_ACCEPT'] == "1"){
$paypal = "Yes";
else
$paypal = "No";
}
For each field, which is tedious and seems like there must be a better way than using an if clause for each field. If so, what is it?
0
source to share
5 answers
Building on what has already been suggested:
// $columns = string array of column names
// $columns = array('PAYPAL_ACCEPT' ... );
foreach($columns as $column) {
$$column = $row[$column] ? 'YES' : 'NO';
}
then you can access the variables using the column names as the variable names:
print $PAYPAL_ACCEPT;
+1
source to share