By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

[PDO] Setting value to "nbsp;" if empty?

P: n/a
Hello

Some of the columns are empty, and must be turned into "nbsp;" so
that an empty cell is shown when displayed in HTML.

This code, however, doesn't work (meaning: I get an empty line instead
of "nbsp;"), but I don't know how else to loop through each column in
the current row:

========
$sql = "SELECT * FROM phones";

foreach($dbh->query($sql) as $row) {

foreach($row as $key =$val) {
if(!$val)
$val="nbsp;";
}

print $row['phones_name'] . "<p>";

}
========

Any idea why?

Thank you.
Feb 17 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Gilles Ganault wrote:
Hello

Some of the columns are empty, and must be turned into "nbsp;" so
that an empty cell is shown when displayed in HTML.

This code, however, doesn't work (meaning: I get an empty line instead
of "nbsp;"), but I don't know how else to loop through each column in
the current row:

========
$sql = "SELECT * FROM phones";

foreach($dbh->query($sql) as $row) {

foreach($row as $key =$val) {
if(!$val)
$val="nbsp;";
}

print $row['phones_name'] . "<p>";

}
========

Any idea why?

Thank you.
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.

And BTW - the code is "&nbsp;". You're missing the leading ampersand.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Feb 17 '08 #2

P: n/a
On Sun, 17 Feb 2008 16:49:31 +0100, "Rik Wasmus"
<lu************@hotmail.comwrote:
>Then you should do a:
foreach ($row as $key =&$val) {
I didn't know that structure. Is it refering to the value's address?
>Offcourse, this is probably better solved with a css empty-cells
property...
Nice to know, although it doesn't look nice if the cell is empty and
the only one on the row:

http://img407.imageshack.us/img407/6...ptycellrz0.jpg

Thanks.
Feb 17 '08 #3

P: n/a
On Sun, 17 Feb 2008 14:13:12 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>Yes, they are two different operations. The query returns a result set
from the database, and the fetch gets a single row from the result set.
I can live with that. Thanks.
Feb 17 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.