Aug 29, 2020 06:43 AM
(This post was last modified: Aug 29, 2020 06:44 AM by blackcoder00.)
hi guys i have a problem i wanna extract sum of integer value from a specify month
exemple : 2020-11-05
Total sum = 14500 $ where date = 2020-11-05
PHP Code
<?php $getdatetwo = $_POST['two']; $res=mysqli_query($con,"SELECT sum(gagner) from benefice where MONTH('date') = '$getdatetwo' ");
PHP Code
<?php <select name="two" class="dropdown-select">
<option>- MONTH -</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May </option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9"> September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select>
i have used this code but it doesn't work
PS : date its a column in my DB MONTH(' date')
Writeln('Give me a Target >');
Is your date column varchar or date
(Aug 29, 2020 09:31 AM)Charger Wrote: Is your date column varchar or date
date
Writeln('Give me a Target >');
Remove the single quotes from MONTH()
“Whatever Your Mind Can Conceive and Believe, It Can Achieve.” – Napoleon Hill
^ And I don’t think you can sum a text field
(Aug 30, 2020 04:15 AM)Charger Wrote: ^ And I don’t think you can sum a text field
i have written this code and it's work fine
PHP Code
<?php function convert($moneys){
echo "<td>date Facture " . date("Y-m-d")."</td>";
if (strlen($moneys) == 4) { echo "<td> Total Profite ".$moneys[0].",".$moneys[1].$moneys[2].$moneys[3]."</td>"; }
if (strlen($moneys) == 5) { echo "<td> Total Profite ".$moneys[0].$moneys[1].",".$moneys[2].$moneys[3].$moneys[4]."</td>"; } if (strlen($moneys) == 6) { echo "<td> Total Profite ".$moneys[0].$moneys[1].$moneys[2].",".$moneys[3].$moneys[4].$moneys[5]."</td>"; }
if (strlen($moneys) == 7) { echo "<td> Total Profite ".$moneys[0].$moneys[1].$moneys[2].",".$moneys[3].$moneys[4].$moneys[5].$moneys[6]."</td>"; }if (strlen($moneys) == 8) { echo "<td> Total Profite ".$moneys[0].$moneys[1].",".$moneys[2].$moneys[3].$moneys[4].",".$moneys[5].$moneys[6].$moneys[7]."</td>"; echo "</tr>"; }
}
// end function
// get month years data system /*$date = date('Y',strtotime(date("Y-m-d"))); // 30 $month = date('m',strtotime(date("Y-m-d"))); $totalYears = $date ."-". $month; */ $totalYears = $_POST['two']; $res1=mysqli_query($con,"select gagner from benefice"); $res=mysqli_query($con,"select * from benefice"); while($row=mysqli_fetch_array($res)){
$datesdb = $row['date']; $datedb = date('Y',strtotime($datesdb)); // 30 $monthdb = date('m',strtotime($datesdb)); $totalYearsdb = $datedb ."-". $monthdb;
while ($row1=mysqli_fetch_array($res1)) { if ($totalYearsdb == $totalYears) { $totalSum = $totalSum + $row1['gagner'];
/* echo $totalYearsdb; echo $totalYears;*/
} break;
} }
convert(strval($totalSum));
Writeln('Give me a Target >');
(Aug 30, 2020 04:52 AM)blackcoder00 Wrote: i have written this code and it's work fine
PHP Code
<?php function convert($moneys){
echo "<td>date Facture " . date("Y-m-d")."</td>";
if (strlen($moneys) == 4) { echo "<td> Total Profite ".$moneys[0].",".$moneys[1].$moneys[2].$moneys[3]."</td>"; }
if (strlen($moneys) == 5) { echo "<td> Total Profite ".$moneys[0].$moneys[1].",".$moneys[2].$moneys[3].$moneys[4]."</td>"; } if (strlen($moneys) == 6) { echo "<td> Total Profite ".$moneys[0].$moneys[1].$moneys[2].",".$moneys[3].$moneys[4].$moneys[5]."</td>"; }
if (strlen($moneys) == 7) { echo "<td> Total Profite ".$moneys[0].$moneys[1].$moneys[2].",".$moneys[3].$moneys[4].$moneys[5].$moneys[6]."</td>"; }if (strlen($moneys) == 8) { echo "<td> Total Profite ".$moneys[0].$moneys[1].",".$moneys[2].$moneys[3].$moneys[4].",".$moneys[5].$moneys[6].$moneys[7]."</td>"; echo "</tr>"; }
}
// end function
// get month years data system /*$date = date('Y',strtotime(date("Y-m-d"))); // 30 $month = date('m',strtotime(date("Y-m-d"))); $totalYears = $date ."-". $month; */ $totalYears = $_POST['two']; $res1=mysqli_query($con,"select gagner from benefice"); $res=mysqli_query($con,"select * from benefice"); while($row=mysqli_fetch_array($res)){
$datesdb = $row['date']; $datedb = date('Y',strtotime($datesdb)); // 30 $monthdb = date('m',strtotime($datesdb)); $totalYearsdb = $datedb ."-". $monthdb;
while ($row1=mysqli_fetch_array($res1)) { if ($totalYearsdb == $totalYears) { $totalSum = $totalSum + $row1['gagner'];
/* echo $totalYearsdb; echo $totalYears;*/
} break;
} }
convert(strval($totalSum));
Consider using money_format instead of manually doing the comma
(Aug 30, 2020 05:46 AM)Charger Wrote: Consider using money_format instead of manually doing the comma
hahaha i didn't know that there's a money format in php
Writeln('Give me a Target >');
(Aug 30, 2020 05:46 AM)Charger Wrote: Consider using money_format instead of manually doing the comma
money_format() is deprecated in PHP 7.4.
OP don't rely on this method, check out number_format instead ;)
“Whatever Your Mind Can Conceive and Believe, It Can Achieve.” – Napoleon Hill
|