not showing empty values coming from database

Reply

Join Date: May 2008
Posts: 74
Reputation: servis is an unknown quantity at this point 
Solved Threads: 0
servis servis is offline Offline
Junior Poster in Training

not showing empty values coming from database

 
0
  #1
Jun 16th, 2009
i am getting the list of values from databas table, some values are null, i want to show the values, which are not null. example is as follow,
//sql query 
while ($row =mysql_query($result))
{
$carBrand     =$row['brandName'];
$carMod        = $row['model'];
$carModYear =$row['modYear'];
$regCity        =$row['regCity'];
$demand      =$row['demand'];
//some of them are null, i want to print here only those are not null
}
actully i have no idea how to do it...
please help..
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 68
Reputation: djjjozsi is an unknown quantity at this point 
Solved Threads: 10
djjjozsi djjjozsi is offline Offline
Junior Poster in Training

Re: not showing empty values coming from database

 
0
  #2
Jun 16th, 2009
build tables, and
  1. print "<tr>";
  2. echo "<td>". ( empty($row["brandName"]) ? "-" : (htmlspecialchars($row["brandName"])) )."</td>";
  3. echo "<td>". ( empty($row["model"]) ? "-" : (htmlspecialchars($row["model"])) )."</td>";
  4. echo "<td>". ( empty($row["modYear"]) ? "-" : (htmlspecialchars($row["modYear"])) )."</td>";
  5. echo "<td>". ( empty($row["regCity"]) ? "-" : (htmlspecialchars($row["regCity"])) )."</td>";
  6. echo "<td>". ( empty($row["demand"]) ? "-" : (htmlspecialchars($row["demand"])) )."</td>";
  7. print "</tr>";
Last edited by djjjozsi; Jun 16th, 2009 at 7:55 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 78
Reputation: navi17 is an unknown quantity at this point 
Solved Threads: 5
navi17 navi17 is offline Offline
Junior Poster in Training

Re: not showing empty values coming from database

 
0
  #3
Jun 16th, 2009
here is the simple solution:

while ($row =mysql_query($result))
{
if(!empty($row['brandName'])
{
$carBrand     =$row['brandName'];
}
if(!empty($row['model'])
{
$carMod        = $row['model'];
}
---
---
---
}

this is just a example. modified your code according to your needs.
Defeat the defeat before defeat defeats you.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 68
Reputation: djjjozsi is an unknown quantity at this point 
Solved Threads: 10
djjjozsi djjjozsi is offline Offline
Junior Poster in Training

Re: not showing empty values coming from database

 
0
  #4
Jun 16th, 2009
while ($row =mysql_query($result)) ????????
  1. <?php
  2. include("conn_bd.php");
  3. $sql="select * from table";
  4.  
  5. $result_res=mysql_query($sql) or die(mysql_error());
  6. print "<table border=\"1\">";
  7. if(mysql_num_rows($result_res)>0)
  8. {
  9. while($rows_res=mysql_fetch_assoc($result_res))
  10. {
  11. /* here comes the printed values*/
  12. print "<tr>";
  13. echo "<td>". ( empty($rows_res["brandName"]) ? "&nbsp;" : $rows_res["brandName"] )."</td>";
  14. echo "<td>". ( empty($rows_res["model"]) ? "&nbsp;" : $rows_res["model"] )."</td>";
  15. echo "<td>". ( empty($rows_res["modYear"]) ? "&nbsp;" : $rows_res["modYear"] )."</td>";
  16. echo "<td>". ( empty($rows_res["regCity"]) ? "&nbsp;" : $rows_res["regCity"] )."</td>";
  17. echo "<td>". ( empty($rows_res["demand"]) ? "&nbsp;" : $rows_res["demand"] )."</td>";
  18. print "</tr>";
  19. }
  20. print "</table>";
  21. }
  22. else
  23. echo "No result in res table ...";
  24.  
  25. ?>
Last edited by djjjozsi; Jun 16th, 2009 at 10:07 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC