变量可变

时间:2017-06-07 21:32:22

标签: variables submit

大家好我有一个查询,需要执行一个变量,但该变量是由表单上的select返回的

$obtermaxcampo = "SELECT P$pagina as maxcampo FROM slider_settings where ID = $ID";

如果我定义$pagina = 1它只询问P1,我有12个P&#39。 我的问题是,如果有任何方式在1中启动变量但在提交后删除该定义并给他一个$pagina = $_POST['selectedPagina'];

这是选定的表格

<form action="" method="POST" name="carregarinfo">
    <label>Pagina</label>
    <select name ="selectedPagina" id="selected" >
        <?php for ($k = 1; $k <= $result['max']; $k++){?>
        <option value ="<?php echo $k;?>" <?php if($_POST['selectedPagina'] == $k){echo "selected='$k'"; }?>><?php echo $k;?></option>
        <?php 
            }
        ?>
    </select>
    <label>Campo</label>
    <select name ="selectedCampo" id="selected" >
        <?php for ($z = 1; $z <= $resultmaxcampo['maxcampo']; $z++){?>
        <option value ="<?php echo $z;?>"><?php echo $z;?></option>
        <?php 
            }
        ?>
    </select>
    <input type="submit" name="carregar" id="carregar" value="Carregar">
</form>

1 个答案:

答案 0 :(得分:0)

if(isset($_POST['carregar'])){
    $sql = "SELECT tituloP$pagina as titulopag, Butao, Titulo, Texto FROM slider_settings, slider_config where slider_settings.ID = $ID and slider_config.P_NUM = $pagina and slider_config.Campo = $campo and slider_config.ID = $ID";
    $sqlconnect = $connect->query($sql);
    $sqlresult = $sqlconnect->fetch_assoc();
    $pagina = $_POST['selectedPagina'];
    $obtermaxcampo = "SELECT P$pagina as maxcampo FROM slider_settings where ID = $ID";
    $connectionmaxcampo = $connect->query($obtermaxcampo);
    $resultmaxcampo = $connectionmaxcampo ->fetch_assoc();

}