Jump to content

Archived

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

mikepuerto

Deleting multiple rows... ???

Recommended Posts

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

[code]
$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);
[/code]

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
But the id column contains numbers, so it'll match $line_num and not the line itself :)

Orio.

Share this post


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

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.