-1

I am writing an SQL request in PHP. the request worked fine like this:

$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%'";

I need to add a limit. If I add a LIMIT with a number it works fine:

$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%' LIMIT 5";

but if i use a define:

define( 'PAGING', 2 );
$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%' LIMIT PAGING";

it throws an error:

Undeclared variable: PAGING SQL=SELECT title FROM bibliography Where title LIKE '%%' LIMIT PAGING

However in other parts of the code PAGING works fine. Why this doesn't work and how can I use a define for a limit?

UltraCommit
  • 1,966
  • 5
  • 38
  • 58
  • Tag dbms used. (E.g. LIMIT is product specific.) – jarlh Dec 04 '15 at 08:36
  • 2
    you have defined a constant but is treated in the sql as a string. You need to break out from the quoted string first. `$testQuery = "SELECT title FROM bibliography Where title LIKE '%$search%' LIMIT ".PAGING.";";` – Professor Abronsius Dec 04 '15 at 08:38

1 Answers1

0

Can you pass a variable in query like this instead of constant? (or it must be constant)

$define = 5;
$testQuery = "SELECT `title` FROM `bibliography` Where title LIKE '%$search%' LIMIT $define";  
Standej
  • 716
  • 1
  • 4
  • 11