-2

My query doesn't return everything if an min is in the title.

Code:

$stmt = $db->runQuery("SELECT all * FROM articles WHERE id = :id AND title LIKE CONCAT(:slug, '%')");

$stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
$stmt->bindParam(':slug', $slug, PDO::PARAM_STR);

Example slug: test-4-1

James Z
  • 12,209
  • 10
  • 24
  • 44
Test
  • 47
  • 4

1 Answers1

-1

Thanks everyone for your help,

I fixed it by adding or operators in my query.

SELECT all * FROM articles WHERE id = :id AND title LIKE CONCAT('%', :slug, '%') or title LIKE CONCAT('%', :slug2) and id = :id

And the new :slug2 paramater:

$stmt->bindParam(':slug2', $_get['slug'], PDO::PARAM_INT);
Test
  • 47
  • 4
  • Seems like the question is missing some information. Also `PDO::PARAM_INT` wont work with `test-4-1`. – chris85 Nov 04 '17 at 15:51
  • I'm aware of that, didn't noticed. And which information does it mis? For me nothing. – Test Nov 06 '17 at 15:43
  • The question is about a `-` in the text. This is binding a second value, probably just hiding the real issue, the real issue is unclear though. – chris85 Nov 06 '17 at 15:52