PHP 和复选框检查那些去表 [英] PHP and Checkboxes check ones go to table

查看:35
本文介绍了PHP 和复选框检查那些去表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张这样的桌子:

$query = "select * from pharmacy";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$num1 = mysql_num_fields($result);

if($num>0)
{
    echo "<table border=2>";
    for($i=0;$i<$num;$i++)
    {
        $row=mysql_fetch_row($result);
        echo "<tr>";
        echo"<td><input type='Checkbox' name='p$i'  value='yes' unchecked /></td>";
        echo"<td>$row[0]</td>";

        echo"</tr>";
    }

我想在Mysql的另一个表中插入选中的内容,如何插入每个复选框的文本?

i want to insert the checked ones in my another table in Mysql how can i insert the texts of each check boxes?

推荐答案

首先你必须改变这个 HTML 以便复选框是一个数组

First off all you must change this HTML so that the checkbox is an array

$query = "select * from pharmacy";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$num1 = mysql_num_fields($result);

if($num>0)
{
    echo "<table border=2>";
    for($i=0;$i<$num;$i++)
    {
        $row=mysql_fetch_row($result);
        echo "<tr>";
        echo"<td><input type='Checkbox' name='pi[$i]' /></td>";
        echo"<td>$row[0]</td>";

        echo"</tr>";
    }

然后在操作页面

    foreach($_POST['pi'] as $key=>$value)
    {
    if($value=="on")
    {
    //DO THE INSERT CODE HERE
// the $key is the $i counter in the HTML
// the $value is whether the user selected it no in this case its just on/off
    }
    }

这篇关于PHP 和复选框检查那些去表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆