Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2010
    Posts
    136

    Unanswered: Select Statement only the first row data was get

    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.

    Code:
    $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 outoput 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...

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    may i give you a bit of advice?

    you have multiple threads going on at sitepoint for this same problem, and you are getting confused by them

    don't repost the same questions in this (or any other) site and expect to alleviate your confusion -- that's only going to make things worse
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2010
    Posts
    136
    Okay, I'm sorry...

    i resolved it now with his code:

    Code:
    $sql = "SELECT Ref_No, From_Range, To_Range, Employee_Share FROM $PAYROLL.sss, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID' AND $TotEarn BETWEEN From_Range AND To_Range";
    $rs = $conn2->Execute($sql);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •