我根据自己的知识修改了多个id,我无法使用ajax获取id。我不擅长ajax。我附上了两个代码。谁能告诉我怎么可以解决它的多个ID
的index.php
$query=mysql_connect("localhost","pma","pmapass");
mysql_select_db("testdb",$query);
include("connection1.php");
$result = mysql_query("SELECT * FROM mytable ORDER BY id");
?>
IDNameText
while ($row = mysql_fetch_array($result)) {
?>
<?php echo $row["id"]; ?><?php echo $row["name"]; ?><?php echo $row["text"]; ?>" name="ids" />
" class="onoffswitch-checkbox" id="myonoffswitch<?php echo $row["id"]; ?>"
$query3=mysql_query("select * from mytable where id=$row[id]");
$query4=mysql_fetch_array($query3);
if($query4['text']=="off")
{
echo "checked";
}
?>>
">
}
?>
Ajax.php
$query=mysql_connect("localhost","pma","pmapass");
mysql_select_db("testdb",$query);
if(isset($_POST['value']))
{
$value=$_POST['value'];
$id=$_POST['ids'];
mysql_query("update mytable set text='$value' where id=2");
echo "
You have Chosen the button status as:" .$value."
";}
?>
+0
很难理解你的代码...用php生成js变量名可能不是最好的解决方案......你究竟在做什么?你的按钮在哪里? –
+0
我想用这个按钮隐藏数据。我有更多的10个ID与数据。我想让按钮在每个ID上工作。 –
+0
http://www.freezecoders.com/2013/05/store-value-from-onoff-button-in-mysql-database-using-php-ajax.html –