I have a php script which constructs an array of objects based on HTML input and then displays the results. What I am trying to do is to display the results page by page. Just like Google (or other search engines) display their results. When the user clicks next, the succeeding chunk of results is echoed back to the page.
Doing that with Javascript (a Javascript function is called as onClick event), I have to import the whole array prepared by the PHP script and index it accordingly. Here is part of the script so you know the kind of array
foreach($results as $id => $currentResult)
{
$temp[$i]->id = $id;
$page = get_page_by_id($id);
$temp[$i]->url = $page['url'];
$temp[$i]->title = $page['title'];
$temp[$i]->score = $currentResult->score;
++$i;
}
$temp = qsort($temp);
So $temp is the array I am going to use in Javascript.
This can totally be eliminated by using PHP only but I’m trying to take the load off the server.
To pass value from PHP to js, use in your HTML template something like:
Then in your JS you can use next syntax:
Great stuff, I think.