mikepuerto Posted September 21, 2006 Share Posted September 21, 2006 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] Quote Link to comment Share on other sites More sharing options...
Orio Posted September 21, 2006 Share Posted September 21, 2006 WHERE id='$line'"Should beWHERE id='$line_num'"Also, move the connection and db selection outside of the loop. You dont need to connect everytime :)Orio. Quote Link to comment Share on other sites More sharing options...
mikepuerto Posted September 21, 2006 Author Share Posted September 21, 2006 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... Quote Link to comment Share on other sites More sharing options...
Orio Posted September 21, 2006 Share Posted September 21, 2006 But the id column contains numbers, so it'll match $line_num and not the line itself :)Orio. Quote Link to comment Share on other sites More sharing options...
mikepuerto Posted September 21, 2006 Author Share Posted September 21, 2006 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. Quote Link to comment Share on other sites More sharing options...
mikepuerto Posted September 21, 2006 Author Share Posted September 21, 2006 anyone have any idea? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.