MJJLAM MJJLAM - 2 months ago 6
PHP Question

Loading fetched rows into php array

Below I am trying to send an ajax request when the page loads to get the results of the productID and productName in a given table. There are about 50k rows to be pulled and i've run into some time delay issues due to the organizing and handling of the array on the serverside(php). Looking at the code below I am able to get the first 10k rows to display on the console without a problem but when i query the entire table for all the results, the console returns a blank object, any possible workarounds for this?

function loadProducts() {
jQuery.ajax({
type: "POST",
data:{'x':'x' },
url: 'performanceHelper/loadProductList.php',
dataType: 'text',

success: function (result, textstatus) {
//Removing reference in Firebase
console.log(result);
}
});
}
window.onload = loadProducts();


PHP code

require_once("../connect.php");


$sql = "SELECT productID, productDesc FROM products";


$temp = $dbh->query($sql);


$results = $temp->fetchAll();


echo json_encode($results);

Answer

Like @RiggsFolly mentioned in the comments, what on earth do you want to do with 50000 items in the browser????

However if you have to, since you can get 10k without any issues like you mentioned, i'll suggest you try pagination... create a function to get the items by sending start and limit as parameters.

This way you dont have to send 50k items at once but you can still get your data.