943,634 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 593
  • PHP RSS
Jun 16th, 2009
0

not showing empty values coming from database

Expand Post »
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..
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
servis is offline Offline
82 posts
since May 2008
Jun 16th, 2009
0

Re: not showing empty values coming from database

build tables, and
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
djjjozsi is offline Offline
69 posts
since Jun 2009
Jun 16th, 2009
0

Re: not showing empty values coming from database

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.
Reputation Points: 15
Solved Threads: 6
Junior Poster
navi17 is offline Offline
118 posts
since Oct 2007
Jun 16th, 2009
0

Re: not showing empty values coming from database

while ($row =mysql_query($result)) ????????
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 11
Junior Poster in Training
djjjozsi is offline Offline
69 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: problem with posting a variable
Next Thread in PHP Forum Timeline: Can't find line breaks





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC