Pagination issues with table format

2019-08-21 08:30发布

问题:

Can anyone assist me out there. I am trying to solve this issues. my table was a formerly a normal table and i use below codes to call the values on the statement table and it work perfectly for me, but I am trying to convert the normal tables to a pagination tables as shown below the line drawn

NORMAL TABLE = WORK PERFECTLY

<td data-title="Trns Date">'.$row["tdate"].'</td>  
     <td data-title="Description">'.$row["comments"].'</td>  
    <td data-title="Debit" class="numeric"><?php echo $tx_type == "debit" ? "$&nbsp;" . number_format($amount, 2) : ""; ?></td>
     <td data-title="Credit" class="numeric"><?php echo $tx_type == "credit" ? "$&nbsp;" . number_format($amount, 2) : ""; ?></td>
    ================================================================================PAGINATION TABLES:

But Now i trying to convert it to a pagination table due to the large database, i now use the below code to echo the value on the table. it does not gives me any error on the table, but the value does not show. It just leaves space blank.

The last two rows for amount does not show.

<td>'.$row["tdate"].'</td>  
<td>'.$row["comments"].'</td>  This two rows work ok

But the last two rows for amount values does not show the figures it was blank

<td>'.$row["tx_type == debit ? &nbsp; . number_format($amount, 2)"].'</td>
<td>'.$row["tx_type == credit ? &nbsp; . number_format($amount, 2)"].'</td>

回答1:

The problem is in the way you are trying to decide the transaction type within the array key string.

Perhaps these two lines can help:

<td>' . ($row["tx_type"] == 'debit' ? '&nbsp;' . number_format($row['amount'], 2) : "") . '</td>
<td>' . ($row["tx_type"] == 'credit' ? '&nbsp;' . number_format($row['amount'], 2) : "") . '</td>

Also I assumed the amount is also stored within the $row; if it is intended to be static similarly as in your example, just replace $row['amount'] with $amount and you are set.

This snippet assumes you are iterating over an array like this:

$rows = [                                                                       
    array('tx_type' => 'credit', 'amount' => 123345.697),                       
    array('tx_type' => 'debit', 'amount' => 796543.21),
    //... and so on                         
];