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] Link to comment https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/ 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. Link to comment https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/#findComment-96286 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... Link to comment https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/#findComment-96297 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. Link to comment https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/#findComment-96302 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. Link to comment https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/#findComment-96311 Share on other sites More sharing options...
mikepuerto Posted September 21, 2006 Author Share Posted September 21, 2006 anyone have any idea? Link to comment https://forums.phpfreaks.com/topic/21569-deleting-multiple-rows/#findComment-96328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.