473,661 Members | 2,429 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 2574
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*******@attgl obal.net
=============== ===

Feb 17 '08 #2
On Sun, 17 Feb 2008 16:49:31 +0100, "Rik Wasmus"
<lu************ @hotmail.comwro te:
>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*******@attg lobal.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
10549
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 update the record in MySQL. The problem is, as soon as the "Update" button (type="submit") is pressed, all of the data disappear from the form. How can that be prevented? Here is my code:
1
4190
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 in IE as well as FireFox. This code has been tested on a Win2003 server, IIS6, PHP 5.0.3, mySQL 4.1.8 and it works fine. The problem server is a Win2k server, IIS5, PHP 5.0.4, mySQL 4.1.11.
2
2971
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 the lines of <td><div class="cbtn" onClick="cmdExec('bold',idContent)" onmouseover="button_over(this);" onmouseout="button_out(this);" onmousedown="button_down(this);" onmouseup="button_up(this);"> <img hspace="1" vspace=1 align=absmiddle...
12
47683
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 "&nbsp;" char - the non breaking space. Can this be represented in a grep statement at
5
11175
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 text. Its not doing what I am trying to do. The text shows up as "&ampMyValue"
0
2568
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;" instead of a blank. Never had this happen before, but I am now using Asp.Net 2.0. Ideas please?
7
49918
by: 一首诗 | last post by:
Is there any simple way to solve this problem?
4
5934
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, however and am really struggling with managing sessions in PHP, based on my experiences with managing sessions in ASP. 99.9% of the feedback I have seen when dealing with the errors has referred to having whitespace before the <?php or after the...
3
4303
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 in \anmeldung2.cfm: line 404
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8542
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1740
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.