Nandini Posted July 4, 2011 Share Posted July 4, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/ Share on other sites More sharing options...
Nandini Posted July 4, 2011 Author Share Posted July 4, 2011 I mean i want to display only non empty fields. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238206 Share on other sites More sharing options...
EdwinPaul Posted July 4, 2011 Share Posted July 4, 2011 I mean i want to display only non empty fields. <tr> <?php if($row['accounts'] != ''){ echo "<td>".$row['accounts']."</td>"; } // but you will have a problem with the table-heading... ?> </tr> [code] Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238212 Share on other sites More sharing options...
Nandini Posted July 4, 2011 Author Share Posted July 4, 2011 This is fine. But i have to fit 3 fields into one <tr>. How can i got to next <tr>. Why because we don't know how many fields are filled. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238213 Share on other sites More sharing options...
laPistola Posted July 4, 2011 Share Posted July 4, 2011 <tr> <?php if(!empty($row['accounts'])){ echo "<td>".$row['accounts']."</td>"; } else { echo "<td> </td>"; } ?> </tr> I have added the extra code and used the empty function rather then just a compare Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238214 Share on other sites More sharing options...
Nandini Posted July 4, 2011 Author Share Posted July 4, 2011 hi we don't want empty cells. Check my example in our question. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238216 Share on other sites More sharing options...
laPistola Posted July 4, 2011 Share Posted July 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238221 Share on other sites More sharing options...
priti Posted July 4, 2011 Share Posted July 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238224 Share on other sites More sharing options...
Nandini Posted July 5, 2011 Author Share Posted July 5, 2011 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238421 Share on other sites More sharing options...
Nandini Posted July 5, 2011 Author Share Posted July 5, 2011 Otherwise Tell me how can i run query to get all the filled MySQL fields. I don't want to get empty fields. I don't know which field is empty and which field is not empty. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238425 Share on other sites More sharing options...
priti Posted July 5, 2011 Share Posted July 5, 2011 1. Debug whether your query generate some output or not 2. print_r($row1) . what is the output for $row1?. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238426 Share on other sites More sharing options...
Nandini Posted July 5, 2011 Author Share Posted July 5, 2011 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238427 Share on other sites More sharing options...
priti Posted July 5, 2011 Share Posted July 5, 2011 You have ONLY one row in your response Hence iterate only once. modify foreach($row1 as $k=>$v) { echo '<tr>'; if(isset($k)) echo '<td>'.$v.'</td>'; echo '</tr>'; } Hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238430 Share on other sites More sharing options...
Nandini Posted July 5, 2011 Author Share Posted July 5, 2011 ya its working fine. But how can i set 3 values per row in table. please Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238435 Share on other sites More sharing options...
priti Posted July 5, 2011 Share Posted July 5, 2011 Exactly what you want ?. Put logic inside the for loop for having three columns. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238436 Share on other sites More sharing options...
TeNDoLLA Posted July 5, 2011 Share Posted July 5, 2011 I have to admit, reading through this thread, its again one of the most confusing ones. No idea what you are trying to tell us. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238441 Share on other sites More sharing options...
Nandini Posted July 5, 2011 Author Share Posted July 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238443 Share on other sites More sharing options...
TeNDoLLA Posted July 5, 2011 Share Posted July 5, 2011 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238445 Share on other sites More sharing options...
Nandini Posted July 5, 2011 Author Share Posted July 5, 2011 Its working fine. Thanq very much Quote Link to comment https://forums.phpfreaks.com/topic/241060-check-mysql-fields-are-filled-or-not/#findComment-1238447 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.