通过Ajax将多个PHP变量发布到PHP处理程序
通过Ajax将多个php变量(或数据库表字段)从用作图标的通过Ajax将多个PHP变量发布到PHP处理程序,php,jquery,ajax,variables,Php,Jquery,Ajax,Variables,通过Ajax将多个php变量(或数据库表字段)从用作图标的元素传递给我的处理程序的最佳方式是什么?提前感谢您的帮助 桌子 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
元素传递给我的处理程序的最佳方式是什么?提前感谢您的帮助
桌子
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>
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";
}
我想做的是将字段art\u featured
的值从0更改为1,比如说如果art\u featured
为0,那么我想将数据库字段更新为1,反之亦然。我正在使用jquery ajax通过post发送文章id
,但我不知道如何发送文章特性
字段。因为我想我最终会做这样的事情
if($_POST['art_featured']==0) {
$sql_articles = "UPDATE `app_articles` SET `art_featured` = 1 WHERE `art_id` =".$_POST['art_id'];
}
else {
$sql_articles = "UPDATE `app_articles` SET `art_featured` = 0 WHERE `art_id` =".$_POST['art_id'];
}
}))
这是一种使用多个参数发出ajax请求的可能方法你能粘贴一些代码让我知道你在说什么吗?请等一分钟,谢谢!有没有一种方法可以像data:id=?我想是的,你可以用data替换+variable+:'id=8391283&length=8943&north='&typ=normal,然后参数“north”=你的行
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";
}
if($_POST['art_featured']==0) {
$sql_articles = "UPDATE `app_articles` SET `art_featured` = 1 WHERE `art_id` =".$_POST['art_id'];
}
else {
$sql_articles = "UPDATE `app_articles` SET `art_featured` = 0 WHERE `art_id` =".$_POST['art_id'];
}
('span').click(function(){
jQuery.ajax({type:'POST',
data:'id=8391283&length=8943&north='+variable+'&typ=normal,
url:'yourUrl',
success:function(data,textStatus){alert('success')},
error:function(XMLHttpRequest,textStatus,errorThrown){}
});