I have a form, where the user selects a name and a date. The variable names are $emp_name and $weekEndDate. These values are passed into a function called getEmpByJob($emp_name,$weekEndDate) as shown below.
function getEmpByJob($emp_name,$weekEndDate)
{
$conn = db_connect();
$query = "SELECT substring(job_id,1,5) job_id,details,week_total from time_sheet_detail where emp_name = '$emp_name' and week_end_date = '$weekEndDate'";
$result = mysql_query($query);
// this was added to see what is being passed to mysql.
print("$query");
// this returns an error if the query was messed up.
if (!$query)
{echo mysql_error();}
/if (!$result)
return false;/
$num_results = mysql_num_rows($result);
echo "<p>Number of rows returned: $num_results</p>";
if($num_results ==0)
return false;
$result = db_result_to_array($result);
return $result;
};
Now when I have a look at the query string on my web page, I can see that the variable values that are submitted from the form are passed into the function okay (shown below)
SELECT substring(job_id,1,5) job_id,details,week_total from time_sheet_detail where emp_name = 'Ainsley Glass' and week_end_date = 'December 2, 2001'
When I run this query in MYSQL is returns 2 rows worth of data.
However, when I show the following:
$num_results = mysql_num_rows($result);
echo "<p>Number of rows returned:
I get
Number of rows returned: 0
When I hard code the values of $emp_name and $weekEndDate in my query, i get,
Number of rows returned: 2.
I'm not sure what is going on here. It is very bizarre. The value type of $emp_name and $weekEndDate are strings. Do I need to re-format to the $emp_name and $weekEndDate values as they are passed into the function to get the query string to work?
Need some help with this.
Thanks
Ainsley