|
Posted by Rik on 12/17/92 11:52
David Haynes wrote:
> Greg Scharlemann wrote:
>> David Haynes wrote:
>>> Also, var is deprecated in PHP5.
>> Thanks!
>> Your test case also worked... but I'm going to make my question a
>> little more complicated...
>>
>> That boolean value is going to be written to a MySQL database. I've
>> set the column to be of type Bool (which appears to turn into a
>> Tinyint(1)), is that the best approach? Should I use enum('true',
>> 'false') or some other approach?
>
> I would translate the 0/1 from MySQL into true/false at the lowest
> level I could. It's not all that hard to unroll it as follows:
>
> $result = mysqli_query($sql);
> while( $row = mysql_fetch_assoc($result) ) {
> $isArchived = $row['is_archived'] ? true : false;
> ...
> }
$isArchived = (bool)$row['isarchived'];
it's shorter, and by using $row['is_archived'] ? you're already evaluating
the boolean value.
http://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|