prepare($query); $catalogcount->bindParam(':i', $assettype, PDO::PARAM_INT); $catalogcount->bindParam(':u', $keywordq, PDO::PARAM_STR); $catalogcount->execute(); $catalogcount = $catalogcount->rowCount(); //data for pages $total = $catalogcount; $pages = ceil($total / $limit); $offset = ($page - 1) * $limit; // Prepare the paged query (if keyword isnt empty, it will be used) $catalog = $pdo->prepare($query . ' LIMIT :limit OFFSET :offset'); $catalog->bindParam(':i', $assettype, PDO::PARAM_INT); $catalog->bindParam(':u', $keywordq, PDO::PARAM_STR); $catalog->bindParam(':limit', $limit, PDO::PARAM_INT); $catalog->bindParam(':offset', $offset, PDO::PARAM_INT); $catalog->execute(); //final check to see if page is invalid if ($pages > 0) { if ($page > $pages) { http_response_code(400); } } //construct the json array $jsonData = array( "pageCount" => $pages, "pageResults" => (int)$catalog->rowCount(), "keyword" => $keyword ); foreach($catalog as $item) { $assetid = $item['id']; $assetname = cleanOutput($item['Name']); $price = $item['PriceInAlphabux']; if ($price == 0) $price = "FREE!"; $assetcreatorid = $item['CreatorId']; $creatorname = getUsername($assetcreatorid); $render = ''; if($item['AssetTypeId'] != 3) { $render = getAssetRender($assetid); } else { $render = getImageFromAsset(1466); //1466 is default audio } $itemInfo = array( "id" => $assetid, "name" => $assetname, "price" => $price, "creatorName" => $creatorname, "creatorId" => $assetcreatorid, "thumbnail" => $render ); array_push($jsonData, $itemInfo); } // ... die(json_encode($jsonData));