我想从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 -->