It is necessary to integrate parts of the SQL query, I am interested in lines 3.4 and 13

$num = 6; $page = (int)$_GET['page']; $count = mysql_query("SELECT COUNT(*) FROM table_products WHERE visible = '1'", $connect); $temp = mysql_fetch_array($count); if ($temp[0] > 0) { $tempcount = $temp[0]; $total = (($tempcount - 1) / $num) + 1; $total = intval($total); $page = intval($page); if (empty($page) or $page < 0) $page = 1; if ($page > $total) $page = $total; $start = $page * $num - $num; $qury_start_num = " LIMIT $start, $num"; } 

Here with this request. And is it possible at all?

 if ($filtering != '') { $query .= 'WHERE ' . $filtering . ' ORDER BY ' . $sorting; } else { $query .= 'ORDER BY ' . $sorting; } 
  • 3
    Learn to write a question correctly and clearly. So far, what you need is clear only to you - Aleksey Shimansky

1 answer 1

As I understand it, you need to have visible = '1' and $filtering in one condition. To do this, you must use SQL AND & OR Operators . In your case, it would look like:

 $query = 'SELECT * FROM table_products WHERE visible = '1' AND '; if ($filtering != '') { $query .= ' $filtering . ' ORDER BY ' . $sorting; } else { $query .= 'ORDER BY ' . $sorting; } 

Again, if I understand correctly what you want:

ps:

  • in 2016, to use the functions "mysql" to put it mildly - not very. Use "PDO" or "mysqli".