Jump to content


Photo

Help with array


  • Please log in to reply
2 replies to this topic

#1 mclard

mclard
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 01 September 2006 - 08:19 AM

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:
$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>";  

Remove script
$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");


#2 samshel

samshel
  • Members
  • PipPipPip
  • Advanced Member
  • 837 posts

Posted 01 September 2006 - 08:36 AM

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>";

$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");

Cheers,
SamShel
-----------------------------------------------
--: FUTURE IS LINUX :--
-----------------------------------------------

#3 mclard

mclard
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 01 September 2006 - 09:00 AM

Thanks, works a treat.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users