473,507 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
3 2567
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10544
by: Mark | last post by:
A beginner in this area, I have been able to read a record from a MySQL database and populate an HTML form (wow!). Now, my goal is to allow the user to edit the contents of the form and then...
1
4178
by: Michael Brennan-White | last post by:
If I submit my for using a get action the resulting page loads . If I use a post action I get an error page saying "The page cannot be found". I am calling the originating page!!! This happens...
2
2956
by: David Bradbury | last post by:
I currently have an iframe on a webpage into which users can insert content. They can further customise the text as I've included buttons such as Bold, Italic, Bullet point etc. This is done along...
12
47482
by: Robert Mark Bram | last post by:
Hi All, I am using the following trim function: function trim (str) { return str.replace(/^\s*/g, '').replace(/\s*$/g, ''); } The problem is that this doesn't trim instances of the...
5
11132
by: Naveen K Kohli | last post by:
I am try to set the text of the drop down list item as ListItem li = new ListItem(); li.Text = "&nbsp;"+"MyValue"; myDropDown.Items.Add("li); The intent is to add a spacing in front of the...
0
2547
by: K B | last post by:
Hi again, I have a gridview, when I get the selecteditem.cells for a column, if the database column is Null or Empty, and I assign that to my web form text control, the control reads "&nbsp;"...
7
49835
by: 一首诗 | last post by:
Is there any simple way to solve this problem?
4
5919
by: three-eight-hotel | last post by:
I'm somewhat of a newbie to PHP coding, but have developed a site using the technology, and have been pleasantly surprised by the capabilities offered. I am more comfortable in the ASP world,...
3
4285
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.