前端知识学习

实现功能

有一个按钮和一个输入框 输入框输入 按钮点击以后 执行php代码

通过表单提交

<div id="side-tab3">
            <h2>批量获取数据</h2>
            <p>根据cid 获取所有商品名称</p>
            <form action="admin.php#side-tab3" id="form_get_all_name" method="post">
                <input type="text" id="cid_all_name" name="cid_all_name">
                <button class="btn btn-success cid_all_name">获取</button>
            </form>
            <div>
                <?php echo $cid_data ?>
            </div>
        </div>

$cid_data可以在文件php代码中顶部处理

function getCidAllNamme($con, $name)
{
    $sql = "select `name` from `la_goods` where `cid`='{$name}'";
    if (!$obj = mysqli_query($con, $sql)) {
        die(mysqli_error($con) . $sql);
    }
    $nameList = array();
    while ($res = mysqli_fetch_assoc($obj)) {
        $nameList[] = $res;
    }
    $cid_data = '';
    if (count($nameList) > 0) {
        $cid_data .= "['";
        //python 中数组的表示方法  ['','']
        foreach ($nameList as $item) {
            $cid_data .= "'".$item['name']."'";
        }
        $cid_data .= "']";
    }
    return $cid_data;
}
 
$cid_all_name = $_POST['cid_all_name'];
if (!empty($cid_all_name)) {
    $cid_data = getCidAllNamme($con, $cid_all_name);
}