Question

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

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.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello,

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,
                    firstname,
               FROM users
              WHERE lastname LIKE :lastname OR 
                    firstname LIKE :firstname;';

    $q = $pdo->prepare($sql);
    
    $q->execute([':lastname' => $POST['lastname'],
        ':firstname' => $POST['firstname']]);
    
    $q->setFetchMode(PDO::FETCH_ASSOC);
    
    // 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:

https://www.digitalocean.com/community/tutorials/how-to-use-the-pdo-php-extension-to-perform-mysql-transactions-in-php-on-ubuntu-18-04

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

https://www.digitalocean.com/community/tutorials/how-to-query-the-database-in-laravel-with-eloquent-select

Hope that this helps. Regards, Bobby