I´m building a small application with Jquery and PHP. Jquery (index.html) adds Form Fields for the User and sends those to a PHP Script (pdo.php). The PHP Script fetches Values from the Database and does some calculations with the User given Values and the Values from the DB. The sum is returned to the Form Page.
index.html <-> pdo.php
Thus I am trying to understand the PHP MVC pattern my question is if
a.) this would make sense in this case.
b.) if so, which part would be what. index.html --> view; pdo.php --> model; controller --> ?
thanks for your help,
tony
Cut-out
jquery ... index.html
$(document).ready(function(){
$("#buttonAjax").click(function(){
var name = encodeURI($("#name").val());
$.ajax({
type: "POST",
url: "pdo.php",
data: "name="+name,
success: function(data){
var json = $.parseJSON(data);
$("#output").html(json.summe);
talk(json.say);
}
});
});
function talk (say){
jQuery.noticeAdd({text: say,stay: false});
}
});
pdo.php
/* DB Connection */
$strDbLocation = 'mysql:dbname=test;host=localhost';
$strDbUser = 'root';
$strDbPassword = 'root';
try{
$objDb = new PDO($strDbLocation, $strDbUser, $strDbPassword);
}
catch (PDOException $e){
echo 'Failure: ' . $e->getMessage();
}
/* Fetch POST Data */
$id = $_POST['name'];
/* Build query */
$dbSelect = $objDb->prepare("SELECT Age,Name FROM Benutzer WHERE id = :id");
$dbSelect -> setFetchMode(PDO::FETCH_ASSOC);
$dbSelect -> bindParam('id', $id);
$dbSelect -> execute();
/* Output + Calculate */
while($row = $dbSelect->fetch()) {
$total = $row['Age'] / 100 . "<br />";
}
/* Return to User */
if(!empty($total)){
$ret = Array("summe" => "Summe: " . $total, "say" => "all right");
echo json_encode($ret); }
else{
$ret = Array("summe" => "Nothing for you", "say" => "nothing for you");
echo json_encode($ret);
}