Jump to content

Check Mysql fields are filled or not


Nandini

Recommended Posts

Hi

 

I have database table 'credit' as follows

 

idaccountspaidchargecurrentpast

10543[/td][td]3465

 

So i want to display the output as follows (this is in table format. Each value divisible by <td>)

 

accounts: 543current: 34past: 65

 

If accounts field not filled (means empty) output like this  (this is in table format. Each value divisible by <td>)

 

current: 34past: 65

 

How can i do this with PHP

Link to comment
https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/
Share on other sites

Show us the code you have.

 

If you don't want empty cells the only other way would be to use colspan like eg

 

if(!empty($row['accounts'])) {
    echo "<td>$row['accounts']</td>";
    echo "<td>$row['paid']</td>";
} else {
    echo "<td colspan=\"2\">$row['paid']</td>";
}

 

This properly isn't what your after but untill I see code I don't understand anymore what your after.

Considering, you have your result set in $results.

 

echo '<table>';

foreach($results as $k=>$v)

{

  echo '<tr>';

    foreach($v as $field)

  {

      if(trim($field['colname']) != '')

          echo '<td>'.$field['colname'].'</td>';

  }

  echo '</tr>';

}

echo '</table>';

 

Hope it helps.

 

I am getting errors by using this code.

 

Warning: Invalid argument supplied for foreach() in

 

here is my code

 

 

<?php
$sql=mysql_query("select * from report where report_id='28'");
$row1=mysql_fetch_assoc($sql);
echo '<table>';
foreach($row1 as $k=>$v)
{
   echo '<tr>';
    foreach($v as $field)
   {
       if(trim($field['accounts']) != '')
          echo '<td>'.$field['accounts'].'</td>';
   }
   echo '</tr>';
}
echo '</table>';
?>

output for $row1 is:

 

Array ( [id] => 28 [property_id] => 691 [report_id] => 28 [no_records] => 0 [bankruptcy] => 0 [foreclosure] => 0 [accounts] => 45 [collection] => [title] => [mortgagerepo] => [mortgagechargeoff] => [paid_off] => [charge_off] => [past_due] => [current] => [unknow] => [publicrecords] => 34 [judge] => [repos] => [summary] => 1 [comments] => [comments1] => [id_date] => 06/24/2011 15:47:46 )

I got a final array like this

 

Array ( [0] => id: 28 [1] => property_id: 691 [2] => report_id: 28 [3] => no_records: 0 [4] => bankruptcy: 0 [5] => foreclosure: 0 [6] => accounts: 45 [7] => publicrecords: 34 [8] => summary: 1 [9] => id_date: 06/24/2011 15:47:46 )

 

I want to display 3 values per row. But same values coming for every row. Here is my code.

 

<?php
echo "<table border='1' width='400'>";
$thumbrows=count($credit_array)/3;
for($r=0;$r<$thumbrows;$r++) { 
echo '<tr>';
for($c=0;$c<3;$c++) {
echo '<td>'.$credit_array[$c].'</td>';
}
echo '</tr>';
}
echo "</table>";  
?>

 

Can any one tell me what is the problem.

Do you mean like this?

 

$testArray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

echo '<table border="1"><tr>';
foreach($testArray as $key => $value)
{
if ($key%3 === 0 && $key > 0)
{
	echo '</tr><tr>';
}
echo '<td>'. $value .'</td>';
}
echo '</tr><table>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.