Jump to content

Help with array


mclard

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.