【问题标题】:Select value from PHP table and pass it to another PHP page从 PHP 表中选择值并将其传递给另一个 PHP 页面
【发布时间】:2016-08-22 15:28:54
【问题描述】:

这些值来自数据库。我想从表中选择一行并将这些值传递给名为 OInfo.php 的下一个 PHP 页面。我尝试使用 Javascript 并将这些值放在文本框中,但是当我单击继续按钮时,即使使用请求方法也无法获取这些值。我能做什么?

<form action="OInfo.php" METHOD="POST">
<div class="table-responsive"> 
<table class="table table-hover table-datatable table-striped table-bordered" id="tableresult">
<thead>
  <tr>
    <th><center>Sección</center></th>
    <th><center>Espacios Disponibles</center></th>
    <th><center>Tiempo de espera</center></th>
    <th><center>Opciones</center></th>
  </tr>
</thead>

 <!---Start of code--->
<tbody>
    <?php
        $query="SELECT * FROM department where dept_id='$id'";
        $result1 = mysql_query($query);
        $row1 = mysql_fetch_array($result1);
        $list = explode(",", str_replace("'", "", substr($row1['dept_schedule'], 0, (strlen($row1['dept_schedule'])+0))));

        foreach($list as $value){
            echo "<tr>";
            echo "<td><center>$value</center></td>";
            echo "<td><center>20</center></td>";
            echo '<td><center><input type="radio" name="select" value="select">  Seleccionar</center></td>';
            echo "</tr>";
        }
    ?>
    <input type='text' name="schedule" id="schedule" value="<? php $value ?>">

</tbody>
<!---End of code--->
</table>

</div>
    <div class='inputWrapper'>
        <input type='text' name="schedule" id="schedule" >
    </div> 
</div>

</form>

<?php
     echo '<a href="OInfo.php?id='.$data['dept_id'].'"><input type="submit" value="Continuar" class="btn btn-primary" style="float:right;"></a>';
?>

这是javascript代码:

<script>
    $('#tableresult tr').click(function(event) {
        $('td', this).each(function(i) {
            $('.inputWrapper input').eq(i).val(this.textContent);
        });
     });
</script>

【问题讨论】:

  • 离题,但看看 mysqli / PDO,而不是 mysql_ - 让这个现场直播会很不安全。
  • 您的提交按钮回显应该在表单标签内。为什么它在
  • &lt;?php echo $value; ?&gt;&lt;?= $value ?&gt;

标签: javascript php mysql forms html-table


【解决方案1】:

有空格value="&lt;? php $value ?&gt;"&gt;应该是value="&lt;?php echo $value ?&gt;"&gt;

【讨论】:

    【解决方案2】:
               **// Comment: Put Everything in input hidden feild and then use on next page ...**
              <table id="example" align="center" cellspacing="0">
                <thead bgcolor="#999999">
                    <tr>
                    <th>heading1</th>           
                    <th>heading2</th>
                    <th>heading3</th>
                    </tr>
                </thead>
                <tbody>
                    <?php 
                    if(isset($list))
                    {
                        $counter = 1;
                        foreach($list as $val)      
                        {   
                          ?>      
                            <form action="OInfo.php" method="post">     
                            <tr>
                            <td>{{$counter++}}</td>
                            <td>{{$val->name}}</td>
                            <td>{{$val->mobile}}</td>
                            <input type="hidden" name="id" value="{{ $val->id}}">
                            <td> 
                            <input class="btn btn-success" type="submit" value="Pay" >     
                            </td>
                            </tr>
                           </form>
    
                           <?php
                        }                                                           
                    }
                </tbody>
    

    【讨论】:

      猜你喜欢
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-27
      • 2014-03-23
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多