Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Bottom Line: How to append array values to the HTML Table cell in PHP ?

Detailed Situation: I have an array like this:

PHP
Array
(
    [PROD-150] => Cancelled
    [PROD-80245] => Pending
    [PROD-BOOK-65] => Due
)


And I have a HTML table like this:
HTML
<tr>
   <th>Order Code</th>
   <th>Order Date</th>
   <th>Customer Code</th>
   <th>Customer Name</th>
   <th>Products Code</th>
   <th>Products Image</th>
   <th>Products Name</th>
   <th>Product Amount</th>
   <th>Commission Percentage</th>
   <th>Commission Amount</th>
   <th>Order Status</th>
   <th>Payment Status</th>
</tr>


Here's the how values are shown in the above table:
PHP
foreach ($affiCodeAndAmount as $key => $value) {
    $query = "SELECT * FROM products WHERE ProdCode = '".$key."'";
    $validate->Query($query);
    while ($rows = $validate->FetchAllDatas()) {
        foreach ($prdOrdQty as $i) {
            $productTotalAmount = $i * $rows["ProdRate"];
        }
        echo "
        <tr>
            <td>".$orderCode."</td>
            <td>".$orderDate."</td>
            <td>".$customerCode."</td>
            <td>".$customerName."</td>
            <td>".$key."</td>
            <td align='center'>
                <img src='//placehold.it/50x50'>
            </td>
            <td>".$rows["ProdName"]."</td>
            <td>".$productTotalAmount."</td>
            <td>".$rows["ProdAffiCommission"]."</td>
            <td>".$value."</td>
            <td>".$status."</td>";
            foreach($array as $val) { // $array is the above array
                "<td>".$val."</td>";
            }
        </tr>";
    }
}


When I run the code, the Payment Status Column is like this:
CancelledPendingDue

I want to display the array values in each cell separately with respect to the number of products. It should be like this:

PHP
<th>Payment Status</th>
    <td>Cancelled</td>
    <td>Pending</td>
    <td>Due</td>


How do I achieve that ? Kindly help me out. Thanks.

P.S.:: All the values are coming from the database. So the table data can vary accordingly.. It can be any x number.
Posted
Comments
Peter Leow 7-Feb-15 0:51am    
How to determine the payment status of each product? based on number of product? then which number goes with which payment status?
Mehul Bawadia 7-Feb-15 0:52am    
When the administrator changes the value of that particular product, the respective user will be notified in his my account.
Peter Leow 7-Feb-15 1:11am    
You have not answered my query. You have 3 statuses in payment status, viz Cancelled,Pending,Due, how does the application know which status to display? or is it going to be a dropdownlist where the user can then select?
Mehul Bawadia 7-Feb-15 1:20am    
The administrator will update the payment status. Administrator account has dropdownlist where in he can select the statuses. Once done and updated, it will be notified to the respective user in his my account. That user only have the option to view it, he can not edit it.
Peter Leow 7-Feb-15 1:25am    
So what column (field) in the returned resultset from the database table that indicates the payment status?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900