php - Need help on variable COUNT query -


i have below function in model. have table called item_like. in table, have 2 columns - saturn_1 , like_id. want total count of like_id when saturn_1 equals value of 'id' => $item->id in array. pretty new coding , can't figure out wrong.

tx help.

public static function formatcallbackchallenge($item, $template = 'challenges') {     static $extensions = null;     if($extensions === null) {         $extensions = extensions_model_front::getbymethod('item_list');     }      $item_title = (strlen($item->title) > 25) ? substr($item->title, 0, 25) . '...' : $item->title;      $db = jo_db::getdefaultadapter();     $total_likes = new jo_db_expr('(select count(like_id) item_like item = $item->id limit 1)');       $data = array(         'template' => $template,         'sql_row' => isset($item->sql_row) ? $item->sql_row : null,,         'id' => $item->id,         'title' => $item_title,         'total_likes' => $total_likes,     );        if($extensions) {         $front = jo_front::getinstance();         foreach($extensions $id => $ext) {             $data_ext = call_user_func(array($front->formatmodulename($ext . '_model_item'), 'listing'), $data, $item);             if($data_ext && is_array($data_ext)) {                 $data = array_merge($data, $data_ext);             }         }     }     return $data;  } 

i don't know database library you're using, , i'm assuming query runs returns wrong data... base on you're looking see 2 errors...

  1. a php error, $item->id not parsed inside of single quoted php.
  2. limit 1 redundant, , may cause problem.

rewrite 9th line inside of method this:

$total_likes = new jo_db_expr("select count(like_id) item_like item = {$item->id}"); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -