RRPANDEY RRPANDEY - 1 year ago 149
PHP Question

Fetching data from database using ajax and php

Below filmdetails.php file i want to call on href click, how i can incorporate the same using ajax for mobile app. i mean when i click on link filmdetails.php?id=12 then below code will fetch the 12 id having data associated with it such as name and year of the film

I want to process this using ajax. please guide



$filmId = $_GET['filmId'];

$sql ="SELECT * FROM films where filmId ='$filmId'";
mysqli_query("SET NAMES utf8");
$result = mysqli_query($conn, $sql);

while($row = mysqli_fetch_array($result))
$id = $row['filmId'];
$name = $row['filmName'];
$year = $row['filmYear'];

echo "$name, $year";



Answer Source

suppose your a tag has id named getcountry, than use

$(document).ready(function() {
    $('#getcountry').click(function() {
            method: "POST",
            url: "filmdetails.php",
            data: { filmId: <?php echo $_GET['filmId']; ?> }
        }).done(function( msg ) {
            alert( "Data Saved: " + msg );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download