php - Multiple while <option> update with query -
i'm trying achieve update query multiple <options>
while loop. using feature assign position id's images can place them on various positions in website. have working single image, means have update each image manually.
in current situation running form inside while loop. submit button posts data process file , saves. works. each image individually.
i want able update image positions single submit button.
in current code think problem run form inside while loop. using data multiple forms in single query not possible if right. i'm writing request noticing more of business logic error- trying wrap head around work.
lets situation/code:
it works this:
option > button
option > button
each update button directs file 'photopositions.php' article id , executes insert query.
i want situation:
option
option
update button
resulting in: update images single click.
the insertquery on photopositions.php looks this:
$insertquery = ("update images set posid = '".$_post['posid']."' id = '".$_post['imgid']."'"); mysql_query($insertquery) or die(mysql_error());
(i know mysql_
depcrecated, i'll try work on later)
my current edit article code looks this:
<?php echo 'images:<br>'; echo '<table width="100%" cellspacing="3">'; $get_photo = "select * images artid = ".$_get['id']." order posid asc"; $result = mysql_query($get_photo) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo '<td align="left"> <a href="../photos/'.$row['name'].'" target="_blank"> <img src="../photos/'.$row['name'].'" width=200> </a>'; ?> <form name="imageposition" method="post" action="photopositions.php?id=<?php echo $_get['id'];?>"> <input type="hidden" name="imgid" id="imgid" value="<?php echo $row['id'];?>"> <select name="posid" id="posid"> <?php echo '<option value="1"'; if($row['posid'] == 1) { echo ' selected'; } echo '>article</option>'; echo '<option value="2"'; if($row['posid'] == 2) { echo ' selected'; } echo '>sidebar</option>'; echo '<option value="4"'; if($row['posid'] == 4) { echo ' selected'; } echo '>offline</option>'; ?> </select> <input type="submit" name="position change" value="position change"> </form> <?php } echo '</table>' . "\r\n"; ?>
the image positions part of larger edit screen form. i'm trying integrate photopositions update 1 update process whole edit article- instead of doing each image manually..
do have output posid data imgid data array , process data query? of course have fix form in while issue assume.
the way change <select name="posid">
array $row['id']
key <select name="posid[$row['id']]">
<?php echo 'images:<br>'; //move form tag outside of table echo '<form name="imageposition" method="post" action="photopositions.php?id=<?php echo $_get['id'];?>">'; echo '<table width="100%" cellspacing="3">'; $get_photo = "select * images artid = ".$_get['id']." order posid asc"; $result = mysql_query($get_photo) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo '<td align="left"> <a href="../photos/'.$row['name'].'" target="_blank"> <img src="../photos/'.$row['name'].'" width=200> </a>'; ?> <select name="posid[<?php echo $row['id']; ?>]" id="posid<?php echo $row['id']; ?>"> <?php echo '<option value="1"'; if($row['posid'] == 1) { echo ' selected'; } echo '>article</option>'; echo '<option value="2"'; if($row['posid'] == 2) { echo ' selected'; } echo '>sidebar</option>'; echo '<option value="4"'; if($row['posid'] == 4) { echo ' selected'; } echo '>offline</option>'; ?> </select> <input type="submit" name="position change" value="position change"> <?php } echo '</table></form>' . "\r\n"; ?>
then in photopositions.php
can foreach loop
foreach($_post['posid'] $key => $value){ $insertquery = ("update images set posid = '".$value."' id = '".$key."'"); mysql_query($insertquery) or die(mysql_error()); }
Comments
Post a Comment