Question

Hi I've searched for a solution to this and found several answers and after many edits to the code and no success I'm asking here directly.

$return_arr = array();
$fetch = tep_db_query("select * from products, " . TABLE_PRODUCTS_DESCRIPTION . " WHERE products.products_status = '1' and products.products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id and " . TABLE_PRODUCTS_DESCRIPTION . ".language_id = '" . (int)$languages_id . "' and " . TABLE_PRODUCTS_DESCRIPTION . ".products_name LIKE '%" . $_GET['term'] . "%'  LIMIT 0,10");
if($fetch === FALSE) {
    die(mysql_error());
}
while ($row = mysql_fetch_assoc($fetch)) 
{
   array_push($return_arr, $row['products_name']);
}  
print json_encode($return_arr);

This returns: mysql_fetch_assoc() parameter 1 resource, object given in ... on line 6

I get where it is, just can't seem to find the problem.

Thanks in advance

Était-ce utile?

La solution

Use tep_db_fetch_array()

  $return_arr = array();
  $fetch = tep_db_query("select * from products, " . TABLE_PRODUCTS_DESCRIPTION . " WHERE products.products_status = '1' and products.products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id and " . TABLE_PRODUCTS_DESCRIPTION . ".language_id = '" . (int)$languages_id . "' and " . TABLE_PRODUCTS_DESCRIPTION . ".products_name LIKE '%" . $_GET['term'] . "%'  LIMIT 0,10");

  echo $fetch; die;
  if($fetch === FALSE) {
      die(mysql_error());
  }
  while ($row = tep_db_fetch_array($fetch))
  {
     array_push($return_arr, $row['products_name']);
  }  
  print json_encode($return_arr);

string mysqli_real_escape_string ( mysqli $link , string $escapestr )

link- A link identifier returned by mysqli_connect() or mysqli_init() escapestr- The string to be escaped.

You can find an example http://php.net/manual/en/mysqli.real-escape-string.php the first parameter needs to be the link identifier returned by mysqli_connect()

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top