php loop from database
up vote
0
down vote
favorite
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;
}
php html loops serialization
add a comment |
up vote
0
down vote
favorite
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;
}
php html loops serialization
Maybe you could loop through$data
once to filter the data and create new arrays based on all the categories that you have. Then loop through those new arrays one by one afterwards to get them neatly categorised based on each of their categories.
– Dirk Scholten
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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;
}
php html loops serialization
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;
}
php html loops serialization
php html loops serialization
edited yesterday
marvinIsSacul
25214
25214
asked yesterday
Yosef Dadya
42
42
Maybe you could loop through$data
once to filter the data and create new arrays based on all the categories that you have. Then loop through those new arrays one by one afterwards to get them neatly categorised based on each of their categories.
– Dirk Scholten
yesterday
add a comment |
Maybe you could loop through$data
once to filter the data and create new arrays based on all the categories that you have. Then loop through those new arrays one by one afterwards to get them neatly categorised based on each of their categories.
– Dirk Scholten
yesterday
Maybe you could loop through
$data
once to filter the data and create new arrays based on all the categories that you have. Then loop through those new arrays one by one afterwards to get them neatly categorised based on each of their categories.– Dirk Scholten
yesterday
Maybe you could loop through
$data
once to filter the data and create new arrays based on all the categories that you have. Then loop through those new arrays one by one afterwards to get them neatly categorised based on each of their categories.– Dirk Scholten
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372033%2fphp-loop-from-database%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe you could loop through
$data
once to filter the data and create new arrays based on all the categories that you have. Then loop through those new arrays one by one afterwards to get them neatly categorised based on each of their categories.– Dirk Scholten
yesterday