Author Topic: Strange Variable problem with SQL Query, pls Help!  (Read 1046 times)

pcinvent

  • Beginner
  • *
  • Posts: 19
    • PCinvent Studio
Strange Variable problem with SQL Query, pls Help!
« on: July 02, 2008, 07:09:43 am »
In the product detail page, I already wrote the code to incrementally increase the view counter each time when user browse the product.

Then in the browse page, I tired to output the counter base on the product_id.

I don't know why the variable $product_id in the SQL query here doesn't work. ??? :-[

* If I replace $product_id in query with specific product id, let say "5", the hit_counter will return correctly.
* I also try the var_dump to determine if this function received the passed reference $product_id correctly or not. The result if positive.

So what else will the problem be? Here is the code I wrote in ps_product,
Anyone who knows how to fix or know why, please kindly give me a hand, thank you in advance!

Code: [Select]
function get_product_hit($product_id) {
//var_dump($product_id);
$db = new ps_DB;
$q = "SELECT hit_counter FROM #__{vm}_product_hit ";
$q .= "WHERE product_id='$product_id'";

$db->query($q);
$db->next_record();
if ($db->f("hit_counter")) {
return $db->f("hit_counter");
}
else {
return false;
}
}