我正在尝试构建一个 CMS,我可以在其中单击星形图标,它将更改art_featured
我数据库中的值,所以说如果art_featured
值为 0,然后单击星形图标,我想将字段的值从 0 更改为 1 . 我有点工作,但我不知道如何传递art_featured
价值,通常我只会id
在我的,span
但我已经在使用它,所以我可以告诉我需要更改哪篇文章,所以我怎么能得到art_featured
我的语句的值,所以我可以运行 if 和 else 语句,然后根据 的值SQL
运行某个语句,SQL
art_featured
提前感谢您的帮助!
桌子
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";
}