Vote count:
0
I want to be able to change the content loaded from an PDO query dynamically, here's what I've got so far and an explanation of what I want:
home.php
<?
session_start();
$category = $_POST['category'];
$tsize = $_POST['tsize'];
$templates = $DB->query("SELECT * FROM templates WHERE category='$category' AND tsize='$tsize'");
echo json_encode(array('category' => $category, 'tsize' => $tsize ));
?>
<button id="test" onclick="changeTemplate('title', 'shape')">Test</button>
<ul class="overview" id="templatesk20" style=" display: none;">
<?php
while
($one = $templates->fetch()) {
?>
<li>
<a class="thumbnail" data-price="<?= $one['price'] ?>" data-id="<?= $one['id'] ?>">
<img id="imgTemp" onclick= "changeImage('../files/templates/blank/<? echo($one['id'])?>.jpg', '../files/shapes/<? echo($one['tsize'])?>.png');" src="/files/templates/example/<?= $one['id'] ?>.jpg" alt="<?= $one['titlep'] ?>">
</a>
</li>
<?php
}
?>
test.js
function changeTemplate(title, shape)
{
if (title !== '') {
$.post('home.php', {
'tsize': shape,
'category': title
}, function(data) {
}, 'json');
} else {
alert('Error!');
}
}
My thought was, on pressing the test button the changeTemplate function is initiated, that posts the title and shape parameters as category and tsize and then those are used to execute the PDO query that returns the requested content on screen. Instead I get nothing. If I hardcode $category and $tsize by myself, the content is returned correctly. Am I doing something wrong? Is it possible to change the SQL query dynamically or is it just loaded once?
asked 1 min ago
Aucun commentaire:
Enregistrer un commentaire