-2

i am having a problem with my code i dont understand whats really wrong with it. i want to get the user id against the LoginID from a table in database but its giving an error of

mysql_fetch_assoc() expects parameter 1 to be resource array given.....

calling to function...

$login_id= $_SESSION['a_id'];
$result=$add_task -> get_id_from_login_id($login_id);
while($id=mysql_fetch_assoc($result)) {
 echo $id;
}

and in the function i have this code

$SQL="SELECT id FROM admin WHERE LoginID='$login_id'";
   return $this->execute_sql($SQL);
Qadeer Khan
  • 5
  • 1
  • 6

3 Answers3

0

The error says that there are no results in your query, its may be because of invalid parameters or invalid query. check your connection first then check you query.

0

It seems that $result doesn't get data. Check your query in terminal or phpmyadmin. I often use this one:

$result = mysql_query($sql) or die(mysql_error());
Dima Savva
  • 86
  • 3
-1

Mysqlfetch_assoc returns an array with the columns of your database.

You should use :

while($id=mysql_fetch_assoc($result)) {
 echo $id['LoginID'];
}
rachids
  • 331
  • 1
  • 3
  • 10
  • thanks all of u but i got the error inside the query there should be space as this `$SQL="SELECT id FROM admin WHERE LoginID = '$login_id' ";` – Qadeer Khan Jul 25 '13 at 09:08