1
我试图建立一个CMS,我可以点击一个星形图标,它会改变我的数据库中的art_featured
值,所以说如果art_featured
值为0,我点击我的星形图标我想将字段的值从0更改为1.我有它的工作原理,但我不知道如何通过art_featured
的值,通常我只是我的id
在我的span
,但我是已经在使用,因此我可以告诉哪篇文章需要更改,所以我如何获得art_featured
到我的SQL
语句的值,以便我可以运行if和else语句,然后根据art_featured
的值运行某个SQL
语句,通过数据库字段ID的运行SQL根据字段值
在此先感谢您的帮助!
TABLE
art_id art_title art_company art_featured
1 lorem 1 lorem ipsum 1 1
2 lorem 2 lorem ipsum 2 0
HTML/PHP
<section class="row">
<?php
$sql_categories = "SELECT art_title, art_company, art_id, art_featured FROM app_articles";
if($result = query($sql_categories)){
$list = array();
while($data = mysqli_fetch_assoc($result)){
array_push($list, $data);
}
foreach($list as $i => $row){
?>
<div class="row">
<div class="column two"><p><?php echo $row['art_title']; ?></p></div>
<div class="column two"><p><?php echo $row['art_company']; ?></p></div>
<div class="column one"><span id="<?php echo $row['art_id']; ?>" class="icon-small star"></span></div>
</div>
<?php
}
}
else {
echo "FAIL";
}
?>
</section>
jQuery的
$(".star").click(function(){
var art_id = $(this).attr('id');
$.ajax({
type: "POST",
data: {art_id:art_id},
url: "ajax-feature.php",
success: function(data){
if(data != false) {
}
else {
}
}
});
});
的MySQL/PHP
if(isset($_POST['art_id'])) {
$sql_articles = "UPDATE `app_articles` SET `art_featured` = 1 WHERE `art_id` =".$_POST['art_id'];
if(query($sql_articles)) {
echo "YES";
}
else {
echo "NO";
}
}
else {
echo "FAIL";
}
对不起,我已经有$(document).ready(function {});我忘了包括这一点。我需要知道的是如何将我的sql结果中的php变量传递给我正在更新数据库的sql语句。 – user2201765 2013-03-26 00:14:08
@ user2201765我更新了它。这是你需要的吗? – 2013-03-26 00:51:39