473,388 Members | 1,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

mysql_fetch_assoc

Ok I have a problem! i have a mysql_fetch_assoc that does not recognize the NULL value of the column. however, i want this null to be picked up so i can use it. how can i go about doing that?

Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_assoc($result)) {
  2.  
  3. echo "<customer_id>" . $row['customer_id'] . "</customer_id>";
  4.  echo "<gender>" . $row['gender'] . "</gender>";//
  5.  echo "<language>" . $row['language'] . "</language>";//
  6.  echo "<birthdate>" . $row['birthdate'] . "</birthdate>";//
  7.  echo "<contact_id>" . $row['contact_id'] . "</contact_id>";//
  8.  echo "<insur1_id>" . $row['insur1_id'] . "</insur1_id>";//
  9.  echo "<insur2_id>" . $row['insur2_id'] . "</insur2_id>";//
  10.  echo "<guardian_id>" . $row['guardian_id'] . "</guardian_id>"; //this value is null
  11.  echo "<hearloss_id>" . $row['hearloss_id'] . "</hearloss_id>";
  12.  echo "<equipment_id>" . $row['equipment_id'] . "</equipment_id>";
  13.  

! get data out of this array but it does not recognize the null fields at all.
Nov 25 '08 #1
1 1753
Atli
5,058 Expert 4TB
Hi.

I'm assuming the row is printed, but the NULL field is simply empty?

If that is the case, then that is precisely what is supposed to happen. A NULL is not really a value. It represents that there is no value.
So, when you tell PHP to print a null, it will print nothing.

If you want it to print something, rather than nothing, then you must tell PHP what it is supposed to print. For example:
Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_assoc($result)) {
  2.   $value = ($row['value'] == null ? "NULL" : $row['value']);
  3.   echo "$value\r\n";
  4. }
  5.  
Which would give you a list of values fetched via a query, substituting null fields with the word "NULL".
Nov 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Alucard | last post by:
Hi all. I am a newbie in PHP. Recently I found that there are mainly two ways to fetch mysql(or other DB) data: by object or by array. What is the main differences between them? Will the...
3
by: Paul Lautman | last post by:
Are there any benefits to using mysql_fetch_object() instead of mysql_fetch_assoc()?
3
by: smythe70 | last post by:
How do mysql_query() and mysql_fetch_assoc() actually work? When I submit a query to a MySQL database it goes away, works out what I requested and throws it back at me. When I submit a query...
3
by: saeedeh | last post by:
hi everyone will you please help me solve my problem: i have several tables and i should use them at the same time i.e. i should join them. now i have to get some some information from some of...
2
by: phattymatty | last post by:
I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensional array in order. The order has already been sorted in the array using a...
5
by: clodhoppers18 | last post by:
I am trying to get the following code to work, and I am having some problems: The code goes for actually 110 lines, but I have dismissed what is not needed. The connection and all that works for...
3
sanjay123456
by: sanjay123456 | last post by:
Dear friends , Plz any one tell me What is difference between mysql_fetch_assoc and mysql_fetch_array while both are return associtive array ?
2
by: bytesFTW99 | last post by:
i have an array that is pulling down information from a database that has null values. how can a get the mysql_fetch_assoc to recognize this null value as just empty space to fill in a form as white...
2
by: poreko | last post by:
I am connecting to my database using Object oriented PHP. My query is returning results but at the end of my table,at the bottom of the page I keep having this error when I run my program: Warning:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...

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.