mclard Posted September 1, 2006 Share Posted September 1, 2006 HiIm trying to get my code to list values from a mysql datatbase and for each item have a clickable button which points to a script to remove the item. So far ive got the following but it only ever passes the last item in the array to the delete script. Dunno if this is a long way round what im trying to do but hope someone can help.Code follows:[CODE]$dbname="project";$dbc = @mysql_connect ('localhost', 'root', '') or die (mysql_error());@mysql_select_db("$dbname");$query = "SELECT * FROM filterurl";//run the query and handle the results$result = @mysql_query($query, $dbc);echo "<form method=post action='remove.php'><table>"; while($row=mysql_fetch_array($result)) { echo "<tr><td>$row[1]</td><td><input type='submit' value='REMOVE'><input type='hidden' name='rmurl' value='$row'></tr>"; }echo "</table></form>"; [/CODE]Remove script[CODE]$rmurl = $_POST['rmurl'];echo $rmurl;$dbname="project";$dbc = @mysql_connect ('localhost', 'root', '') or die (mysql_error());@mysql_select_db("$dbname");$SQL = "DELETE FROM filterurl WHERE url = $rmurl";$result = mysql_query($SQL);header("Location: filterdisplay.php");[/CODE] Quote Link to comment https://forums.phpfreaks.com/topic/19336-help-with-array/ Share on other sites More sharing options...
samshel Posted September 1, 2006 Share Posted September 1, 2006 [code]echo "<form method=post action='remove.php'><table>"; while($row=mysql_fetch_array($result)) { echo "<tr><td>$row[1]</td><td><input type='submit' value='REMOVE'><input type='hidden' name='rmurl[]' value='$row[0]'></tr>";//can be 0 or 1 or 2 depending on the element where the url is stored }echo "</table></form>";[/code][code]$rmurl = "'".implode("','",$_POST['rmurl'])."'";echo $rmurl;$dbname="project";$dbc = @mysql_connect ('localhost', 'root', '') or die (mysql_error());@mysql_select_db("$dbname");$SQL = "DELETE FROM filterurl WHERE url in($rmurl)";$result = mysql_query($SQL);header("Location: filterdisplay.php");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19336-help-with-array/#findComment-83893 Share on other sites More sharing options...
mclard Posted September 1, 2006 Author Share Posted September 1, 2006 Thanks, works a treat. Quote Link to comment https://forums.phpfreaks.com/topic/19336-help-with-array/#findComment-83899 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.