动态单选按钮创建及其标签 [英] dynamic radio button creation along with their labels
问题描述
我是一名 php 程序员.我在 Localserver 和数据库表中上传图像(如果是表,则是存储在表、字段中的图像位置.
执行:当我点击检索按钮时,图像正确显示在浏览器中.它采用行式画廊格式(使用css).到目前为止一切都很好.但是如果我尝试为每张照片显示四个单选按钮(就在每张照片的下方以及它们的标签),问题就开始了.这里需要提一下,我已经将四个按钮的四个值的名称存储在一个数组中.
下面是代码片段:
<div class="img"><img src="<?php echo "$resultrow[1]"; ?>"高度="100" 宽度="120"/>
<?php}while($resultrow=mysql_fetch_array($query)){for($i=0;$i<=3;$i++){?><div class="rateselection"><input type="radio" name="select" value="<?php echo "$imagearray[i]";?>"/>
<?php}//为了结束}//虽然结束?>
为了方便起见,退出php并再次进入它,我希望你理解.告诉我我哪里出错了.请注意第一个while"正在正确执行,但第二个while不是.......请提出解决方案
你应该使用一个数组来发布你从单选按钮获得的内容.
例如您可以在输入元素中写入 type='radio' name='array[]'
在您的 PHP 代码中,当您访问 $_POST['array']
时,您将可以访问具有相同名称的所选单选按钮的每个值.
I am a php programmer .I am uploading images in both the Localserver as well as the the database table (in case of table its the image location that is being stored in the table, field.
execution:When I click on a button the retrieve, the images are properly displayed in the browser properly.Its in the row wise gallary format(used css).Everything is fine till now.But the problem starts if I try to display four radio buttons for each photo(just below each photo along with their labels. I need to mention here that I have stored the names of four values of four buttons in an array.
below is the code snippet:
<?php
while($resultrow=mysql_fetch_array($query)){
?>
<div class="img">
<img src="<?php echo "$resultrow[1]"; ?>" height="100" width="120"/>
</div>
<?php
}
while($resultrow=mysql_fetch_array($query)){
for($i=0;$i<=3;$i++){
?>
<div class="rateselection">
<input type="radio" name="select" value="<?php echo "$imagearray[i]";?>"/>
</div>
<?php
}//for ends
}//while ends
?>
coming out of php and going again into it is for convenience,I hope you understand.Just tell me where I went wrong .PLEASE NOTE that the first "while" is executing properly ,but the 2nd while is not....Please suggest a solution
You should use an array for posting what you get from radio buttons.
For example you can write in the input element type='radio' name='array[]'
In your PHP code, when you access $_POST['array']
, you will have access to every value of the selected radio buttons with the same name.
这篇关于动态单选按钮创建及其标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!