If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Select Statement only the first row data was get

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-05-11, 04:45
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
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...
Reply With Quote
  #2 (permalink)  
Old 12-05-11, 06:52
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-05-11, 20:06
newphpcoder newphpcoder is offline
Registered User
 
Join Date: Dec 2010
Posts: 126
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);
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On