0

我想从 MySQL 数据库中选择一行,其中有多行。

我选择了单选按钮进行选择,并将该行的 id 放入单选按钮值中。

问题是已发布的单选按钮已设置,当echo您在代码中看到它时,它会显示正确的 ID。

当我想使用 MySQL 查询从数据库中进行选择时,它给了我和索引未定义的错误,奇怪的是,当我选择一个只包含一行的表时,此代码正在工作,但是当行数超过一个时,我无法选择所选行。

表代码:

<?
if($_SESSION["count"]!=0 || $_SESSION["count"]!="")
{
?>
    <!-- begining of levels informations -->
    <form name="form2"  method="POST" dir="rtl" action=""  style="font-family:'B_yekan';"> 
<div align="center" width="900" >
    <table class="styled-table" cellspacing="0" width="900" border="1">
    <tr>
        <th width="10" scope="col" ></th>
        <th width="60" scope="col">level</th>
        <th width="60" scope="col">date</th>
        <th width="60" scope="col">time</th>    
        <th width="54" scope="col">price</th>
        <th width="60" scope="col">mark</th>
    </tr>
    <?php
    $id = array();
    while($rows=mysql_fetch_array($result)){
    $id[]=$rows['id'];
    ?>
    <tr>
    <td><input class="styled-input" type="hidden" name="id[]" id="id" value= "<? echo $rows['id']; ?>"  /></td>
    <td><input class="styled-input" type="text" name="lev" id="lev" value="<? echo $tbl_name; ?>"  /></td>
    <td><input class="styled-input" type="text" name="date[]"  id="date" value="<? if($rows['date']=="1"){echo "even";}else{echo "odd";}?>" /></td>
    <td><input class="styled-input" type="text" name="time[]" id="time"
                    value="<?if($rows['time']=="pm1"){ echo"16 - 17:30";}
                    elseif($rows['time']=="pm2"){ echo "17:45 - 19:15";}
        elseif($rows['time']=="pm3"){echo "19:30 - 21";}?>" />
                </td> 
    <td><input class="styled-input" type="text" name="price[]" id="price" value= "<? echo $rows['price']; ?>" /></td>

    <td><input class="styled-input" style="padding: 5px;width:20px" type="radio" name="mark[]" id="mark" value="<? echo $rows['id']; ?>" /></td>

</tr>
<?php
 }//end of loop
?>
</table>
</div>
<input class="styled-button-8"  type="Submit" value="firstchoose" name="firstchoose" />

    <?}//end of if check for count?>            
    </form>

选择代码:

<!-- first choose level -->
    <?php
    // Check if button name "Submit" is active, do this 
    if(isset($_POST['firstchoose']) && $_POST['firstchoose'] == 'firstchoose')
        {

         $tbl_name=$_POST['lev'];

         for($i=0;$i<$_SESSION["count"];$i++)
        {

            $checked =mysql_real_escape_string($_REQUEST['mark'][$i]);              
            echo $checked;
            $sql2="SELECT * FROM $tbl_name WHERE `id`='".mysql_real_escape_string($checked)."' ";

            $result2=mysql_query($sql2);
            $data = mysql_fetch_assoc($result2);
            $count2=mysql_num_rows($result2);
        }


        if(isset($result2)){
        ?>
        <script language="javascript">alert('the level is selected successfully.');    </script>
        <?php

        }

    }
    ?>
<!-- end of first choose level -->
4

0 回答 0