954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help diplaying null values

I have a form on my site where members fill in info etc... This info goes into my database, I call to my DB to display this info in a table. My problem is that when someone does not fill in one of the spots in the form this goes to the DB as null and wont show up in my table, this makes my whole table get messed up and won't line up with the users information. My question is how can I get the null values to display null or show up blank in the table cell?

Here is the code I have would I put it

Here:
$sql="select id, name, email from update_table order by id";

Or in the actual table:
<?echo $row2['username'];
?

I have been trying to figure this out for weeks. Someone please help me out. :confused:

eyelove808
Newbie Poster
2 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 
$query ="select id, name, email from update_table order by id"; 
$result = mysql_query($query);
if ($result == 0)
{
   echo "there was an error accessing the database!");
}
else
{
   for ($i=0; $i<mysql_num_rows($result); $i++)
   {
      $row = mysql_fetch_row($result);
      echo "<table><td><tr>\n"; 
      echo "<a href=\"profile.php?user=".$row[0]."\">".$row[1]."</a>
      echo "anything else needed .... yadda yadda yadda ";
   }
}
paradox814
Posting Whiz
351 posts since Oct 2004
Reputation Points: 13
Solved Threads: 4
 

I tried that and it does not work. This is where I put it:

$result1=@mysql_query($sql,$con) or die("woops! not successful 1
$sql");
if ($result == 0)
{
echo "there was an error accessing the database!");
}

eyelove808
Newbie Poster
2 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

Easiest thing to do is to alter your table to have a default value of "blank" rather than NULL. Then you don't have the problem.

However, I don't see that you would have a problem unless you are using if's on the results. If your while loop is something like this:

<?
while ($array = mysql_fetch_array($qry)) { ?>
<? echo $array[id];?>
<? echo $array[name];?>
<? echo $array[hooha];?>
<?
} >

A null value won't mung up the format in the above. How are you killing your table?

barnamos
Junior Poster in Training
50 posts since Mar 2005
Reputation Points: 15
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You