Hi, I`ve started doing PHP and MYSQL for a few months now and I am working on a project for a friend. Basically I had the code written down in mysql format and decided to change my code too mysqli.
Everything was working fine except for one function. I keep getting this error Warning: mysqli_fetch_array() [function.mysqli-fetch-array]: Couldn't fetch mysqli_result .
Here`s my code
connect to database
//DEFINE etc...
function connect(){
//global $dbc;
$dbc = mysqli_connect(HOST, USERNAME, PASSWORD, DB)
or die('Cannot connect to MySQL! '.mysqli_connect_error());
return $dbc;
}
update function
function update_emp_job_position($emp_id, $job_id)
{
$dbc=connect();
// Turn autocommit off.
mysqli_autocommit($dbc, FALSE);
$success = true;
$query = "Update employee set
job_position_id='".$job_id."'
where id = '".$emp_id."'";
if($result = mysqli_query($dbc, $query) or die(mysqli_error()))
{
if(mysqli_affected_rows($dbc)>0)
{
//update training_date by selecting all the employees
$query_sub = "select id, employee_id, job_position_id, training_id, required
from training_date
where employee_id = '".$emp_id."'";
if($result_sub = mysqli_query($dbc, $query_sub) or die(mysqli_error()));
if(mysqli_num_rows($result_sub)>0){
while($row_training_date = mysqli_fetch_array($result_sub, MYSQLI_BOTH)) //this is where i get the error
{
ยจ ..............................
}
I don`t really know why this is happening. I did a var_dump on the mysqli_fetch_array but it just returned NULL.
I echo all my queries and ran them in mysql, and it worked fine.
mysqli_fetch_array() works in other functions on the same page and called on the same page.
this code worked when I used mysql instead of mysqli...
I`m not sure if I should upgrade my php version (5.3.0 using wamp2) because mysqli_fetch_array() works when called else where
thanks to anyone who can help.