Call PHP function on page onload [duplicate]

-1

I want to call a PHP function that is in the same file. I tried this within the HTML code.

<?php select($dir, $base); ?>

And my PHP function:

function select($dir, $base){       
    $base_hndl  =   new SQLite3($dir.$base);                
    $requete    =   "SELECT id, title, start, end, description FROM \"event\" ORDER BY id DESC";
    $resultat   =   $base_hndl->query($requete);     
    $affiche    =   $resultat->fetchArray();

    echo "<br><label><b>ID: $affiche[id]</b></label><br>";
    echo "<label><b>Title: $affiche[title]</b></label><br>";    
}
    
asked by anonymous 25.10.2014 / 20:14

1 answer

1

You can not do this directly.

PHP is a server-side technology not being directly accessible through HTML or Javascript.

To make a PHP call from the onload event, the simplest is to place the function in another PHP file and make an AJAX request for this file. With the response returned, in Javascript you should refresh the HTML to reflect the returned data.

I think you're a beginner, so there's plenty to study here. I recommend you look at the English pages of Wikipedia on PHP, Javascript and AJAX just to get an introduction on what each technology is about.

Then try to build the codes, and if you find more difficulties, write questions detailing the errors and difficulties found.

Wikipedia: Ajax

Wikipedia: JavaScript

Wikipedia: PHP

jQuery

jQuery.ajax

    
25.10.2014 / 20:26