Note that there are some explanatory texts on larger screens.

plurals
  1. POSmall change breaks the mysql query
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2269840/php-pdo-bindvalue-in-limit">PHP PDO bindValue in LIMIT</a> </p> </blockquote> <p>I have this code that works quite well.</p> <pre><code>if (array_key_exists('cat', $_GET) === TRUE) { $category = $_GET['cat']; } else { $category = '.*'; } $conn = new PDO('mysql:host=localhost;dbname=news', 'root', ''); $stmt = $conn-&gt;prepare('SELECT * FROM stories WHERE category RLIKE :cat ORDER BY score DESC LIMIT 0, 25'); $stmt -&gt; execute(array( 'cat' =&gt; $category, )); $result = $stmt-&gt;fetchAll(); </code></pre> <p>As you can see, it gets a category from the get request, and searches the database for everything in that category.</p> <p>I'm also trying to add a bit so that there can be a page defined in the get request, and the query will start 25 rows later for each increase by one in page.</p> <p>Here's what I wrote:</p> <pre><code>if (array_key_exists('cat', $_GET) === TRUE) { $category = $_GET['cat']; } else { $category = '.*'; } if (array_key_exists('page', $_GET) === TRUE) { $page = intval($_GET['page'])*25; } else { $page = 0; } $conn = new PDO('mysql:host=localhost;dbname=news', 'root', ''); $stmt = $conn-&gt;prepare('SELECT * FROM stories WHERE category RLIKE :cat ORDER BY score DESC LIMIT :page, 25'); $stmt -&gt; execute(array( 'cat' =&gt; $category, 'page' =&gt; $page )); $result = $stmt-&gt;fetchAll(); </code></pre> <p>But now, the query is returning nothing, no matter what page is, or if there is a category.</p> <p>Maybe I'm not dealing with integers right. Any idea why I'm getting this result?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload