extracting the middle values of a string
Posted: Thu Jul 23, 2009 7:40 am
Hi, I have a table which contains employees. Each employee has a code. The code indicates the department the employee belongs to the year he joined the organization and a unique number. The format is three digits alphabets, two digits indicating the year and two digits the unique number. Like ‘ABC0503’.
I wanted the digits representing the year and I used this query.
$query = "SELECT SUBSTRING(code,4,5) AS acc
FROM tblEmployee
WHERE (SUBSTRING(code,1,3)= 'ABC' OR SUBSTRING(code,1,3)='XYZ' ";
$result = @mysql_query($query);
$nbrows_batch = @mysql_num_rows($result);
if ($nbrows > 0){
while($rowdata= @mysql_fetch_array($result)){
$empCode = $rowdata['acc'];
}//while($rowdata = @mysql_fetch_array($result))
But I am getting the whole 4 numeric characters. Any suggestiona?
Thanks.
I wanted the digits representing the year and I used this query.
$query = "SELECT SUBSTRING(code,4,5) AS acc
FROM tblEmployee
WHERE (SUBSTRING(code,1,3)= 'ABC' OR SUBSTRING(code,1,3)='XYZ' ";
$result = @mysql_query($query);
$nbrows_batch = @mysql_num_rows($result);
if ($nbrows > 0){
while($rowdata= @mysql_fetch_array($result)){
$empCode = $rowdata['acc'];
}//while($rowdata = @mysql_fetch_array($result))
But I am getting the whole 4 numeric characters. Any suggestiona?
Thanks.