Afficher un message
Vieux 17/02/2008, 16h21   #3
Gilles Ganault
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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)? "&nbsp;":"$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 "&nbsp;"?

Thank you.
  Réponse avec citation
 
Page generated in 0,06826 seconds with 9 queries