1

I currently have the following:

$stmt = $conn->prepare("SELECT COUNT(*) FROM items WHERE quality LIKE :quality AND type LIKE :type AND name LIKE :name ".$amount);
$stmt->bindParam(':quality', $quality);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':type', $type);
$stmt->execute();
$total = $stmt->rowCount();

This will always return 1. Yet when doing:

SELECT * FROM items WHERE quality LIKE :quality AND type LIKE :type AND name LIKE :name ".$amount

It will return all the items that match the query. When doing a broad search the LIKE's will be set to % rather than an actual name due to a search box.

Is this an issue with the LIKE %? I'm needing to get how many items there are within that query so I can see the total amount of pages by doing

$pages = ceil($total / $limit);

$amount is the following:

if ($_GET['amount'] == "2") { $amount = "AND points <=".$result[0]['points']; }
user1372896
  • 542
  • 1
  • 10
  • 27
  • 3
    What is this: ` . . . LIKE :name ".$amount);`? – Gordon Linoff Nov 08 '16 at 12:29
  • Sorry, included that in the main post now. – user1372896 Nov 08 '16 at 12:30
  • If the comment of Gordon isn't clear enough : What is this: `. . . LIKE :name ".$amount);` ? You end up with `LIKE something something` which is wrong and probably the cause of your issue. You should have `LIKE something`... meaning `:name` or `$amount` but not both – Thomas G Nov 08 '16 at 12:53
  • 1
    The problem is that you do your query and return the _rowCount_ . This will always be 1 as you are using an aggregate function (ie, COUNT) with no GROUP BY clause. So your query has brought back a single row with a column which has the count in it, but then instead of using that count you have instead counted the number of rows returned. – Kickstart Nov 08 '16 at 13:17
  • Thanks, doing fetchColumn worked instead. – user1372896 Nov 08 '16 at 14:07

0 Answers0