Re: [PDO] Setting value to "nbsp;" if empty?
On Sun, 17 Feb 2008 09:30:46 -0500, Jerry Stuckle
<jstucklex@attglobal.net> wrote:
>Probably because $val isn't what you expect it to be. Find out what's
>in $val for an empty column and test for that.
Thanks for the tip. It seems like it's only possible to loop once
through the items of an array:
===============
$res = $dbh->query($sql);
if($res) {
while ( $row = $res->fetch(PDO::FETCH_ASSOC) )
foreach ($row as $key => $val) {
$val = (!$val)? " ":"$val";
//GOOD
print "$key = $val\n<p>";
}
//BAD : nothing shown
print $row['contacts_city'] . "<p>";
//BAD: Warning: Invalid argument supplied for foreach() foreach
($row as $key => $val) {
print "$key = $val\n<p>";
}
}
===============
I'd prefer to use an associative array so I can refer to items using
their column names instead of their indexes. Is there a way to do
this, but still go through the array first to check for empty items
and replace them with " "?
Thank you.
|