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;
}









share|improve this question
























  • 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















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;
}









share|improve this question
























  • 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













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;
}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Saint-Aignan (Tarn-et-Garonne)

Volksrepublik China

How to test boost logger output in unit testing?