How to fetch data from mysql using ajax/jquery when passing three different parameter from html form

Posted September 6, 2021 280 views

I have Stream, Academic year, batch and semester as input to fetch students data through php who belongs to these Stream, Academic year, batch and semester passed from html form.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


It would work quite similarly to when receiving a single input instance.

For example let’s say that you wanted to select a user where the user’s last name and first name are specified in your input:

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

    $sql = 'SELECT lastname,
               FROM users
              WHERE lastname LIKE :lastname OR 
                    firstname LIKE :firstname;';

    $q = $pdo->prepare($sql);

    $q->execute([':lastname' => $POST['lastname'],
        ':firstname' => $POST['firstname']]);


    // print out the result set
    while ($r = $q->fetch()) {
        echo sprintf('%s <br/>', $r['lastname']);
} catch (PDOException $e) {
    die("Could not connect to the database $dbname :" . $e->getMessage());

I would also recommend this tutorial here on how to use PDO PHP to perform MySQL transactions:

Also, I could strongly recommend learning Laravel as your first PHP framework, as it makes it easy to interact with your database:

Hope that this helps.

A MySQL transaction is a group of logically related SQL commands that are executed in the database as a single unit. Transactions are used to enforce ACID (Atomicity, Consistency, Isolation, and Durability compliance in an application. This is a set of standards that govern the reliability of processing operations in a database. In this tutorial, you will use the PDO PHP Extension, which provides an interface for working with databases in PHP, to perform MySQL transactions.
  • Thank you for your reply.
    But my question is when i input firstname and lastname pass these data by ajax/jquery and display the result set. To more; Why i want this to improve response time form the server. OR if you have an idea about loading large amount of data from mysql quickly mean no scrolling time.