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
https://forums.phpfreaks.com/topic/19336-help-with-array/
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
https://forums.phpfreaks.com/topic/19336-help-with-array/#findComment-83893
Share on other sites

Archived

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

×
×
  • 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.