URGENT HELP - Multiple Record Update

Discussion in 'Web Design and Development' started by TheCoupe, Feb 13, 2010.

  1. TheCoupe macrumors member

    Joined:
    Mar 4, 2009
    Location:
    Northern Ireland
    #1
    Hi all,

    I am trying to display a group of images from my database and use a Radio Group to select a main image, ie, set all images to a value of 0 in my database, except the one selected, which would have a value of 1. My form is displaying the group properly on the page, but I am stumped as to how to update the multiple rows to achieve this.

    this is my code so far:
    Code:
      <form id="form1" name="form1" method="post" action="">
        <?php do { ?>
          <input name="pic_id[]" type="hidden" id="pic_id" value="<?php echo $row_images['pic_id']; ?>" />
    <input  <?php if (!(strcmp($row_images['pic_default'],"1"))) {echo "checked=\"checked\"";} ?> type="radio" name="radio[]" id="radio" value="1" />
          <img src="/images/for-sale/<?php echo $row_images['pic_image']; ?>" width="80" height="80" />
          <br />
    	  <?php } while ($row_images = mysql_fetch_array($images)); ?>
        <input type="submit" name="Submit" id="Submit" value="Submit" />
      </form>
      <?php echo $totalRows_images; ?>
      <?php
    // Check if button name "Submit" is active, do this
    if($Submit){
    for($i=0;$i<$totalRows_images;$i++){
    $sql1="UPDATE $aani_sale_pics SET pic_default='$radio[$i]' WHERE pic_id='$pic_id[$i]'";
    $result1=mysql_query($sql1);
    }
    }
    
    if($result1){
    header("location:image-upload.php");
    }
    mysql_close();
    ?>
    
    Or am I going about this the whole wrong way? Any suggestions are welcome.

    Thanks in advance :)
     
  2. TheCoupe thread starter macrumors member

    Joined:
    Mar 4, 2009
    Location:
    Northern Ireland
    #2
    Sorted

    Been tearing my hair out on this for the past few days... post for help, then resolve 30 mins later haha... Thanks anyway :)
     

Share This Page