sac0o01 Posted November 4, 2012 Share Posted November 4, 2012 I have a script that fetches image urls from a database and then displays the images on the page. This all works fine but the problem is I cannot remove just one image from the image list. I would like to add a "delete" button below each image that would correspond to that image. Problem is I don't fully understand foreach and how it works with arrays. Here is how I fetch the images: <?php $sqlresult = mysql_query("SELECT * FROM images WHERE user_id =".$_SESSION['userId']); $count = 0; while($data = mysql_fetch_array($sqlresult)) { $image[$count] = $data['url']; $count++; } ?> And here is how I list the images. This is where I want to add the delete button (I know the code is ugly ) : <?php foreach ($image as $image){?> <tr> <td width="70"><center><img src="<?php echo $image;?>" alt="rotation" /><br /> URL:<?php echo $image;?></center></td> </tr> <?php }?> Thanks for any suggestions Quote Link to comment Share on other sites More sharing options...
Jessica Posted November 4, 2012 Share Posted November 4, 2012 Did you look up the manual page on foreach? The Iteration name can't be the same as the source array. Quote Link to comment Share on other sites More sharing options...
sac0o01 Posted November 4, 2012 Author Share Posted November 4, 2012 Yes I have looked through the manual on foreach. That is how I came up with what I have so far. Actually the "$image as $image" part is working but I see it would be better defined by "$image as $image_arr" (or similar). What I am confused on is how to call each value in the array so that I can delete just that value (url) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.