doujiaoben28596 2018-11-19 09:51
浏览 31

从数据库的PHP循环

i have a code that store data in database as an object with serialize(), and show this on table in loop from database each category have 'payment' column that has the array with the payments data (example:[num,string,date]) And there could be several payment to each category, but the issue is that now it show all payments category in the table one under the other i try to do it nicer so that In the column that displays the the payments will be a modal button that displays the payments of each category in the modal but it display the first value on the array to all categories i try someting to give an id But that's impossible because it prints the information in a loop

that's my code:

function showTable($table, $data, &$totalSum = 0)
{
$totalEestimatedCost = 0;
$totalMyBudget = 0;
if (is_array($data)) {
    $tableToShow = '';
    $outputData = '<table class="table table-striped table-hover table-responsive-xs table-responsive-sm table-responsive-md table-responsive-lg" >';
    $outputData .= "
    <thead>
    <tr>
      <th  scope='col'>קטגוריה</th>
      <th  scope='col'>התקציב שלי</th>
      <th  scope='col'>עלות בפועל</th>
      <th  scope='col'>תשלומים</th>
      <th  scope='col'>יתרה לתשלום</th>
      <th  scope='col'>הקובץ</th>
    </tr>
    </thead>
    <tbody>
     ";
    $totalHefresh = 0;
    for ($i = 1; $i < count($data) / 2; $i++) {
        $arrData = unserialize($data[$i]);
        $heb_name = $arrData['data']['field_name_heb'];
        $files = $arrData['data']['files'];
            $myBudget = isset($arrData['data']['my_budget'])?$arrData['data']['my_budget']:0;
              $myBudgetNumber = number_format($myBudget);
        $estimatedCost = isset($arrData['data']['estimated_cost'])?$arrData['data']['estimated_cost']:0;
        $estimatedCostNumber = number_format($estimatedCost);
        $filesData = returnFiles($files, $arrData['data']['field_name'], $arrData['data']['stage']);
        $total_field_cost =  isset($arrData['data']['total_cost'])?$arrData['data']['total_cost']:0;
        $payments = returnPayments($arrData['payments'], $arrData['data']['field_name'], $arrData['data']['stage']);

        $hefresh = $estimatedCost - $total_field_cost;
        $hefreshNumber = number_format($hefresh);
        $totalEestimatedCost += $arrData['data']['estimated_cost'];
        $totalEestimatedCostNumber = number_format($totalEestimatedCost);
        $totalMyBudget += $arrData['data']['my_budget'];
        $totalMyBudgetNumber = number_format($totalMyBudget);
        $totalHefresh += $hefresh;
        $totalHefreshNumber = number_format($totalHefresh);
        $outputData .=
            "<tr>

<td>$heb_name</td>
 <td class='text-center'> <span> ₪ </span> <span>$myBudgetNumber</span>  </td>
<td  class='text-center'> <span> ₪ </span> <span>$estimatedCostNumber</span>  </td>
<td >$payments</td>
<td class='text-center'><span>  ₪ </span> <span>$hefreshNumber</span></td>
<td style='height: 118px'>$filesData</td>
</tr>
</tbody> ";

 //echo "<pre>";
   //print_r($arrData);
    }
    printDinamicDataTable($table , $outputData , $totalEestimatedCost , $totalHefresh);
    $outputData .= "</table>";
    $outputData .= "<div class='total-hfresh'>
    <div>סה\"כ התקציב שלי: $totalMyBudgetNumber</div>
    <div>סה\"כ עלות בפועל: $totalEestimatedCostNumber</div>
    <div>יתרה לתשלום: $totalHefreshNumber</div>

    </div>";
  //echo "<br> $outputData";
    $totalSum += $totalHefresh;
    return $outputData;
    }
   };

  function returnPayments($payments, $field, $stage)
  {
  $dataToReturn = '';
  foreach ($payments as $key => $value) {
    $payment = $value['payment'];
    $date = $value['date'];
    $note = $value['note'];
   $dataToReturn .= "<table style='width: 100%;margin-bottom: 5px'><tr><td 
    class='pay-td1'>₪  $payment </td>";
    $dataToReturn .= " <td class='pay-td2'>$note </td>";
    $dataToReturn .= "<td class='pay-td3'> $date </td>";
    $dataToReturn .= "<td><button data-stage='$stage' data-id='$key' data- 
     name='$field' class='deletePayment btn btn-danger'><b>X</b>                                 
     </button></td></tr></table>";

   }
    return $dataToReturn;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100