samedi 24 octobre 2015

run sql query on button click

The following code reads data from a sqlite database and for each row of the table print a div containing screen_name, description, and three buttons. On the click of each button the div disappears.

I would like to add another feature: on the click of remove button, delete a specific row from the table.

However, I don't know how to do it, since I have all the code inside echo. Any suggestions?

<?php
/* header */
echo "<p align = 'center'>reBot v1.0<br>
web interface</p>";

/* database connection */
$db = new SQLite3('bot.db');
$results = $db->query('SELECT * FROM prospects');
$i = 0;
while ($row = $results->fetchArray()) {
    $screen_name = $row['screen_name'];
    $description = $row['description'];
    $i++;

echo "<script>
$(document).ready(function(){
    $('#approve".$i."').click(function(){
        $('div.profile".$i."').hide();
    });
    $('#skip".$i."').click(function(){
        $('div.profile".$i."').hide();
    });
    $('#remove".$i."').click(function(){
        $('div.profile".$i."').hide();
    });
});
</script>
<div align = 'center' class = 'profile".$i."'>

<p>
<b>".$screen_name."</b><br>
<i>".$description."</i>
</p>

<button id='approve".$i."'>Approve</button>
<button id='skip".$i."'>Skip</button>
<button id='remove".$i."'>Remove</button>
</div>";
}

/* footer */
echo "<div class = 'end' align = 'center'>
<p>You are done!</p>
</div>";
?>

Aucun commentaire:

Enregistrer un commentaire