I am creating a small application with jQuery and PHP. JQuery (index.html) adds form fields to the user and submits them to PHP Script (pdo.php). The PHP script extracts the values ββfrom the database and performs some calculations with the User data, data and values ββfrom the database. The amount is returned to the form page.
index.html β pdo.php
So, I am trying to understand the PHP MVC pattern, my question is what
a.), that would make sense in this case.
b.) if so, which part would be which. index.html β view; pdo.php β model; controller β?
thank you for your help,
Tony
Cutaway
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
$strDbLocation = 'mysql:dbname=test;host=localhost';
$strDbUser = 'root';
$strDbPassword = 'root';
try{
$objDb = new PDO($strDbLocation, $strDbUser, $strDbPassword);
}
catch (PDOException $e){
echo 'Failure: ' . $e->getMessage();
}
$id = $_POST['name'];
$dbSelect = $objDb->prepare("SELECT Age,Name FROM Benutzer WHERE id = :id");
$dbSelect -> setFetchMode(PDO::FETCH_ASSOC);
$dbSelect -> bindParam('id', $id);
$dbSelect -> execute();
while($row = $dbSelect->fetch()) {
$total = $row['Age'] / 100 . "<br />";
}
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);
}
source
share