开发者

dynamic radio button creation along with their labels

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.


should be $i not i

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


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


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..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜