The essence of the problem was altered by the plug-in. Favorites for your site, the structure was slightly different .

the differences in the structure of the product and members base in my original items and users

All this works with the exception of two things are not displayed categories and the user the author of the goods for the place it displays the user of the current session.

Tell me where I have a mistake

the structure of the table I did this

-- -- Структура таблицы `favorites` -- CREATE TABLE IF NOT EXISTS `favorites` ( `user_id` int(11) NOT NULL, `item_id` int(11) NOT NULL, `datetime` datetime NOT NULL, PRIMARY KEY (`item_id`), KEY `item_id` (`item_id`,`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- -- Дамп данных таблицы `favorites` -- INSERT INTO `favorites` (`user_id`, `item_id`, `datetime`) VALUES (1, 2, '2015-11-25 19:54:04'), (1, 3, '2015-11-25 19:54:15'); 

Converted class

  class favorites extends base { public $usersWhere = ''; public function getAll($start = 0, $limit = 0, $where = '', $order = "`datetime` DESC") { global $mysql; $limitQuery = ''; if ($limit != 0) { $limitQuery = " LIMIT $start, $limit "; } if ($where != '') { $where = " WHERE " . $where; } $mysql->query(" SELECT * FROM `favorites` $where ORDER BY $order $limitQuery "); if ($mysql->num_rows() == 0) { return false; } $return = array(); $this->usersWhere = ''; while ($d = $mysql->fetch_array()) { $return[] = $d; if ($this->usersWhere != '') { $this->usersWhere .= ' OR '; } $this->usersWhere .= " `user_id` = '" . intval($d['user_id']) . "' "; } $this->foundRows = $mysql->getFoundRows(); return $return; } public function get($itemID) { global $mysql; $mysql->query(" SELECT * FROM `favorites` WHERE `item_id` = '" . intval($itemID) . "' "); if ($mysql->num_rows() == 0) { return false; } return $mysql->fetch_array(); } public function isInFavorites($itemID, $userID) { global $mysql; $mysql->query(" SELECT * FROM `favorites` WHERE `item_id` = " . intval($itemID) . " AND `user_id` = " . intval($userID) . " "); if ($mysql->num_rows() == 0) { return false; } return true; } public function getItems($userID, $start = 0, $limit = 0, $where = '', $order = '`fav`.`datetime` DESC') { global $mysql; $mysql->query(" SELECT * FROM `favorites` WHERE `user_id` = " . intval($userID) . " "); if ($mysql->num_rows() == 0) { return false; } $whereQuery = ''; while ($d = $mysql->fetch_array()) { if ($whereQuery != '') { $whereQuery .= ' OR '; } $whereQuery .= " `fav`.`user_id` = " . intval($d['user_id']); } $limitQuery = ''; if ($limit != 0) { $limitQuery = " LIMIT $start, $limit "; } $mysql->query(" SELECT * FROM `items` LEFT JOIN `favorites` as fav ON `fav`.`item_id` = `items`.`id` WHERE ($whereQuery) $where ORDER BY $order $limitQuery "); if ($mysql->num_rows() == 0) { return false; } $this->usersWhere = ''; $return = array(); while ($d = $mysql->fetch_array()) { $categories = explode('|', $d['categories']); unset($d['categories']); $d['categories'] = array(); $row = 0; foreach($categories AS $cat) { $categories1 = explode(',', $cat); foreach($categories1 as $c) { $c = trim($c); if ($c != '') { $d['categories'][$row][$c] = $c; } } $row++; } $return[$d['id']] = $d; if ($this->usersWhere != '') { $this->usersWhere .= ' OR '; } $this->usersWhere .= " `user_id` = '" . intval($d['user_id']) . "' "; } $this->foundRows = $mysql->getFoundRows(); return $return; } public function add($itemID, $userID) { global $mysql; if ($this->isInFavorites($itemID, $userID)) { return false; } $mysql->query(" INSERT INTO `favorites` ( `user_id`, `item_id`, `datetime` ) VALUES ( '" . intval($userID) . "', '" . intval($itemID) . "', NOW() ) "); return true; } public function delete($itemID, $userID) { global $mysql; if (!$this->isInFavorites($itemID, $userID)) { return false; } $mysql->query(" DELETE FROM `favorites` WHERE `user_id` = '" . intval($userID) . "' && `item_id` = '" . intval($itemID) . "' "); return true; } } 

Conclusion

 _setView(__FILE__); _setTitle($langArray['favorites']); require_once ROOT_PATH . '/market/apps/favorites/models/favorites.class.php'; $favoritesClass = new favorites(); $limit = 10; $start = (PAGE - 1) * $limit; $order = ''; if (!isset($_GET['sort'])) { $_GET['sort'] = ''; } switch($_GET['sort']) { default: $order = '`fav`.`datetime`'; $sort = $langArray['date']; break; } abr('sort', $sort); if (!isset($_GET['order']) || $_GET['order'] == '' || $_GET['order'] == 'desc') { $_GET['order'] = 'desc'; $order .= ' DESC'; } else { $_GET['order'] = 'asc'; $order .= ' ASC'; } $items = $favoritesClass->getItems($_SESSION['user']['user_id'], $start, $limit, " AND status = 'active' ", $order); if (is_array($items)) { require_once ROOT_PATH . '/market/apps/users/models/users.class.php'; $usersClass = new users(); $users = $usersClass->getAll(0, 0, $favoritesClass->usersWhere); abr('users', $users); } abr('items', $items); require_once ROOT_PATH . '/market/apps/categories/models/categories.class.php'; $categoriesClass = new categories(); $categories = $categoriesClass->getAll(); abr('categories', $categories); abr('paging', paging('/favorites/?p=', '&sort=' . $_GET['sort'] . '&order=' . $_GET['order'], PAGE, $limit, $favoritesClass->foundRows)); 

html

  {if $items} <div class="row"> {foreach from=$items item=p} <div class="col-md-4"> <div href="/{$languageURL}items/{$p.id}/{$p.name|url}" onclick="location.href ='/{$languageURL}items/{$p.id}/{$p.name|url}'" class="hover"> <div class="bottom-grup"> <a class="material-icons md-20" href="">&#xE87D;</a> <a class="material-icons" href="">&#xE03B;</a> </div> </div> <div class="item"> <img src="{$data_server}uploads/items/{$p.id}/{$p.thumbnail}" alt="{$p.name|escape}" class="thumbnail"> </div> <div class="meta"> <div class="price"> {$currency.symbol}{$p.price|string_format:"%.0f"} </div> <div class="name text-truncate"> <a href="/{$languageURL}items/{$p.id}/{$p.name|url}">{$p.name}</a> </div> <div class="user text-truncate"> От <a class="pop" data-href="/users/ajax-user-info/{$users[$p.user_id].username}" href="/user/{$users[$p.user_id].username}">{$users[$p.user_id].username}</a> В {foreach from=$p.categories item=e} {foreach from=$e item=c name=foo} <a href="/categories/{$categories[$c].id}/{$categories[$c].name|url}.html">{$categories[$c].name}</a> {if !$smarty.foreach.foo.last} &#xf105; {/if} {/foreach} {/foreach} </div> </div> </div> {/foreach} </div> {/if} 

Perhaps the problem is somewhere here.

 public function getItems($userID, $start = 0, $limit = 0, $where = '', $order = '`fav`.`datetime` DESC') { global $mysql; $mysql->query(" SELECT * FROM `favorites` WHERE `user_id` = '".intval($userID)."' "); if ($mysql->num_rows() == 0) { return false; } $whereQuery = ''; while ($d = $mysql->fetch_array()) { if ($whereQuery != '') { $whereQuery .= ' OR '; } $whereQuery .= " `fav`.`user_id` = '".intval($d['user_id'])."' "; } $limitQuery = ''; if ($limit != 0) { $limitQuery = " LIMIT $start, $limit "; } $mysql->query(" SELECT * FROM `items` LEFT JOIN `favorites` AS fav ON `fav`.`item_id` = `items`.`id` WHERE ($whereQuery) $where ORDER BY $order $limitQuery "); if ($mysql->num_rows() == 0) { return false; } $this->usersWhere = ''; $return = array(); while ($d = $mysql->fetch_array()) { $categories = explode('|', $d['categories']); unset($d['categories']); $d['categories'] = array(); $row = 0; foreach($categories AS $cat) { $categories1 = explode(',', $cat); foreach($categories1 as $c) { $c = trim($c); if ($c != '') { $d['categories'][$row][$c] = $c; } } $row++; } $return[$d['id']] = $d; if ($this->usersWhere != '') { $this->usersWhere .= ' OR '; } $this->usersWhere .= " `user_id` = '".intval($d['user_id'])."' "; } $this->foundRows = $mysql->getFoundRows(); return $return; } 

    0