Jump to content


Photo

Deleting multiple rows... ???


  • Please log in to reply
5 replies to this topic

#1 mikepuerto

mikepuerto
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 September 2006 - 07:47 PM

Can anyone give me an idea as to why this does not work? I dont get any errors and it seems to run fine but does not delete the rows...

$file = $_GET['file'];
$lines = file($file);

foreach ($lines as $line_num => $line) {
	$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to the database');
	mysql_select_db($dbname);
	$query = "DELETE FROM largo1 WHERE id='$line'";
	$result = mysql_query($query);
	echo "$line deleted<br>";
}
mysql_close($conn);


#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 21 September 2006 - 07:55 PM

WHERE id='$line'"
Should be
WHERE id='$line_num'"

Also, move the connection and db selection outside of the loop. You dont need to connect everytime :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 mikepuerto

mikepuerto
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 September 2006 - 08:02 PM

i took your suggestion on the db connection and select but...
actually $line_num is the row number. $line is the data that i'm trying to use to delete the row...



#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 21 September 2006 - 08:07 PM

But the id column contains numbers, so it'll match $line_num and not the line itself :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 mikepuerto

mikepuerto
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 September 2006 - 08:18 PM

The id column contains an auto_increment id. Each line of the file contains an ID that exists in the table. Therefore $line is the ID that I'm trying to delete. Not thinking about it very much i changed id="$line_num" resulting in the deletion of a a bunch of rows that i did not want to delete.

I have figured out that the script works. but it does not actually loop. It only deletes one.

#6 mikepuerto

mikepuerto
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 21 September 2006 - 08:47 PM

anyone have any idea?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users