Jump to content

Archived

This topic is now archived and is closed to further replies.

mclard

Help with array

Recommended Posts

Hi
Im 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]

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.