dynamic radio button creation along with their labels

天涯浪子 提交于 2020-01-17 00:42:10

问题


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


回答1:


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.




回答2:


should be $i not i

<input type="radio" name="select" value="<?php echo "$imagearray[$i]";?>"/>



回答3:


You probably need to reset the query cursor, or just re-execute the query. Here's how to reset the cursor:

http://us2.php.net/manual/en/function.mysql-data-seek.php




回答4:


it will not run because you already iterated thorugh the result array, you either need to rewind it or save it while looping through it first... etc..



来源:https://stackoverflow.com/questions/4691458/dynamic-radio-button-creation-along-with-their-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!