Jump to content


Check out our Community Blogs

newphpcoder

Member Since 07 Sep 2010
Offline Last Active May 05 2014 09:34 PM
-----

#631945 Need Help In Using If Condition To Select Query

Posted by newphpcoder on 17 June 2012 - 11:50 PM

It should be something like this. Make sure the space before CLASS_NIL (or what you call it) is there, as there needs to be a space between classes.

<td colspan="2" class="{$attendance[att].LOGIN_CLASS}{if $attendance[att].LOG_IN == "0000-00-00 00:00:00"} CLASS_NIL{/if}">{$attendance[att].LOG_IN}</td>


Hi...

where this class :CLASS_NIL came from???


Thank you
  • 1


#628448 Sum Values Inside Foreach And While Loop

Posted by newphpcoder on 27 April 2012 - 06:30 PM

Hi..
I have table which has a data so_month:
FromMonth : 5
ToMonth : 7
and I have table working_days:
MonthName
May
Jun
Jul
MonthNumber
05
06
07
WorkingDays
23
24
23
Now I have function to get the 3 consecutive months from FromMonth to ToMonth , which as you can see from May to Jul
Now I have problem in getting the SUM of Working days.
here is my code:

<?php
$sql = "SELECT FromMonth, ToMonth FROM so_month";
$res = mysql_query($sql,$con);
$row = mysql_fetch_assoc($res);
$FromMonth = $row['FromMonth'];
$ToMonth = $row['ToMonth'];
function monthNames($from, $to){
$range=array();
for($i=$from; $i<=$to; $i++){
$range[$i]=date('M', mktime(0,0,0,$i));
}
return $range;
}
$month_ = implode("' ', ",monthNames($FromMonth,$ToMonth));
foreach( monthNames($FromMonth, $ToMonth) as $month){
$sql = "SELECT MonthName, SUM(WorkingDays) AS WorkingDays FROM working_days WHERE MonthName IN ('$month') GROUP BY MonthName";
$res = mysql_query($sql, $con);
while($row = mysql_fetch_array($res)){
$WorkingDays = $row['WorkingDays'];
}
echo $WorkingDays;
}
?>

the output of this code is:
232423
and when I change this line:
$WorkingDays = $row['WorkingDays'];
to
$WorkingDays += $row['WorkingDays'];
the output is:
234770
The correct output should be: 70
Any help is highly appreciated.
Thank you very much..
  • 1


#627026 For Loop Did Not Work

Posted by newphpcoder on 16 April 2012 - 12:42 AM

Hi..
I am new in using for loop to get the values from while loop:
here is my code:

$sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items";
$res_bom = mysql_query($sql, $con);
while($row = mysql_fetch_assoc($res_bom)){

$Items = $row['Items'];
echo "<tr>
<td style='border: none;font-weight: bold;'>&nbsp;<input type='name' value='$Items' name='Items[]' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td>
<td style='border:none;'>&nbsp;</td>
<td style='border:none;'>&nbsp;</td>
<td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty[]' value='' size='7'></center></td>

</tr>";
}

sample:
Items -- I input demanded qty
P28 -----1
P30------2
P32------3
when I debug my script by checking if what data was get bhy using for loop:

$Items = $_POST['Items'];
$DemandedQty = $_POST['DemandedQty'];
for($s = 0; $s <= count($Items); $s++){

echo $DemandedQty[$s];
echo '<br/>';
echo $Items[$s];

}

the ouput is:
3
P28
P30
P32
I don't know why only the last demanded qty was get.
I want output is :
P28- 1
P30- 2
P32 - 3
Thank you
  • 1


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download