Reputation: 57
i am working on an table layout. If there is x ammount of rows it will then go to the next row.
However de modulo is giving me an error when its trying to divide it by 0.
This is normal i know.
How can i check if the data is NULL and then returns next row with no data in it.
$j=0;
foreach($PortalName as $data1){
$countQuery = $db->query('SELECT *, COUNT(gold_sended) as total_runs FROM gold_sended WHERE gold_sended.user_id = "'.$data1[1].'" AND (gold_swap_id = "'.$db->real_escape_string($_GET['a']).'") AND (week = "29") ORDER BY date DESC');
while($count = $countQuery->fetch_assoc()) {
if($j % $count['total_runs'] == 0 && $j > 0) {
echo '</tr><tr>';
}
echo '<td>'.number_format($count['gold_sended']).'</td><td bgcolor="Yellow"><font color="#000">'.$count['date'].'</font></td>';
$j++;
}
}
total_runs is for some player 0 because they haven't sended anything. So if an player has not sent anything it must output an empty row. If there is data. proceed with the rest of the code.
Any tips will be appriciated.
Edit: Almost done but they layout is still not correct. the code is now as follow
<?php
$j=0;
foreach($PortalName as $data)
{
if($data[2] == 0) { echo '</tr><td> </td><tr>'; } else if($data[2] > 0 && $j % $data[2] == 0 && $j > 0) { echo '</tr><tr>'; }
$countQuery = $db->query('SELECT * FROM gold_sended WHERE gold_sended.user_id = "'.$data[1].'" AND (gold_swap_id = "'.$db->real_escape_string($_GET['a']).'") AND (week = "29") ORDER BY date DESC');
while($count = $countQuery->fetch_assoc())
{
echo '<td>'.number_format($count['gold_sended']).'</td><td bgcolor="Yellow"><font color="#000">'.$data[4].'</font></td>';
}
$j++;
}
?>
This will generate the following output
However this is not correct. Because Fred has only sended 150000000
The rest is for the next member.
Ok its solved now. Changed this row
if($data[2] == 0) { echo '</tr><td> </td><tr>'; } else if($data[2] > 0 && $j % $data[2] == 0 && $j > 0) { echo '</tr><tr>'; }
to
if($data[2] == 0) { echo '</tr><td> </td><tr>'; } else if($data[2] > 0 && $j % $data[2] == 0 && $j > 0) { echo '</tr><tr>'; } else { echo '</tr><tr>'; }
Its producing now the correct layout.
Thank you all
Upvotes: 0
Views: 287
Reputation: 474
you can check if total_runs
is empty and use continue
keyword to skip to the next item of your loop
if(empty($count['total_runs'])) {
// put your table row ending code here
continue;
}
Upvotes: 0
Reputation: 187
use "continue" statement to do this
if($count['total_runs'] == null || $count['total_runs'] == 0) {
continue;
}
Upvotes: 0
Reputation: 3040
With in your if statement add a validation that total_run not == 0
if($count['total_runs']1>0 && $j % $count['total_runs'] == 0 && $j > 0) {
Upvotes: 1