Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Victor Nugraha
Victor Nugraha
9,115 Points

PHP: Using variable in Limit Clause failing

I'm trying to incorporate a 'load more' function to my website through ajax, one of the challenge is to increase the 'limit' on each SQL request. Can someone point out which line is failing? Than you

  <?php
    include 'connection.php';
    $newcount = $_POST['newpict'];
    //Create Template
    $temp = "SELECT * FROM inspiration LIMIT ?";
    //Create prepared statement
    $stmt = mysqli_stmt_init($db);
    //Prepare the prepared statement
    if(!mysqli_stmt_prepare($temp, $stmt)){
      echo "SQL statement failed";
    } else {
      //Bind Parameters to the placeholder
      mysqli_stmt_bind_param($stmt, "i", $newcount);
      //Run parameter inside database
      mysqli_stmt_execute($stmt);
      $result = mysqli_stmt_get_result($stmt);
    }

    $row = mysqli_fetch_assoc($result);

    do {
   ?>
  <div class="col1 isection-1-temp">
      <img src="Picture/Inspiration/<?php echo $row['Picture']?>" class="isection-1-img">
  </div>
  <?php
    } while ($row = mysqli_fetch_assoc($result));
   ?>