Jump to content

Select Statement only the first row data was get

- - - - -

  • Please log in to reply
No replies to this topic

#1
newphpcoder

newphpcoder

    Programming Professional

  • Members
  • PipPipPipPipPipPip
  • 474 posts
Good day!

I have table for the list of range and the equal deduction based on their total earnings.

here is the fields from table sss

Ref_No
From_Range
To_Range
Salary_Credit
Employee-Share

Sample data
Ref_No 1
From_Range 1000
To_Range 2000
Salary Credit 1500
Employee Share 50

Ref_No 2
From_Range 3000
To_Range 4000
Salary Credit 3500
Employee Share 150

And so on..

I have this test code to check if all data was selected for reference in condition to get the employee share based on their totalernings.:

$TotEarn is not already save in the database, it was only display in the webpage.


$TotEarn = round(($Amount + $OTReg_Amt + $SunReg_Amt + $OTSun_Amt + $HolReg_Amt + $HolRegOT_Amt + $HolLeave_Amt + $NP_Amt + $Meal_Amt + $Cola_Amt), 2);


$smarty->assign('TotEarn', $TotEarn);


$sql = "SELECT Ref_No, From_Range, To_Range, Employee_Share FROM $PAYROLL.sss, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";

$rs = $conn2->Execute($sql);


$Ref_No = $rs->fields['Ref_No'];

$From_Range = $rs->fields['From_Range'];

$To_Range = $rs->fields['To_Range'];

$Employee_Share = $rs->fields['Employee_Share'];       

                                                        


if($Ref_No == 1 AND $Totearn >= $From_Range AND $TotEarn <= $To_Range){

    echo $Employee_Share;

}

elseif($Ref_No == 2 AND $TotEarn >= $From_Range AND $TotEarn <= $To_Range){

    echo $Employee_Share;

}

elseif($Ref_No == 3 AND $TotEarn >= $From_Range AND $TotEarn <= $To_Range){

    echo $Employee_Share;

}

else{

    echo 0;

}  


the result is only one data has the correct output and the rest the output is 0.

How can I get all the data not only the first row in the database, because i need to used it in if, elseif , else condition.

Thank you so much...




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users