Carl-Cox- Posted September 16, 2003 Share Posted September 16, 2003 grr this is annoying me i cant fink its late why wont it delete all from the database [php:1:885a98dab3] $result = mysql_query(\"SELECT * FROM xdcc\", mysql_connect(\"localhost\",\"***\",\"***\")); $countDB = mysql_num_rows($result); echo $countDB.\" Rows <BR>\"; $tempno = \"1\"; while ($tempno <= $countDB){ $query = \"DELETE * FROM xdcc WHERE id = \'$tempno\'\"; $result = mysql_query($query); $tempno++; } [/php:1:885a98dab3] its counts teh rows and add to $tempno each time but the query isnt working Link to comment https://forums.phpfreaks.com/topic/1023-why-doesnt-it-delete/ Share on other sites More sharing options...
PHPcadet Posted September 16, 2003 Share Posted September 16, 2003 Are you trying to delete all the records from the table? If so, there is an easier way using the truncate command. See: http://www.phpfreaks.com/mysqlmanual/page/...e.html#TRUNCATE Link to comment https://forums.phpfreaks.com/topic/1023-why-doesnt-it-delete/#findComment-3477 Share on other sites More sharing options...
DylanBlitz Posted September 16, 2003 Share Posted September 16, 2003 Just do $query = \"DELETE FROM xdcc WHERE id = \'$tempno\'\"; don\'t need the * Link to comment https://forums.phpfreaks.com/topic/1023-why-doesnt-it-delete/#findComment-3478 Share on other sites More sharing options...
DylanBlitz Posted September 16, 2003 Share Posted September 16, 2003 One thing I don\'t understand, tempno is always going to be 1, and your deleting where the id is 1 every time? Link to comment https://forums.phpfreaks.com/topic/1023-why-doesnt-it-delete/#findComment-3479 Share on other sites More sharing options...
mydsmbr Posted September 17, 2003 Share Posted September 17, 2003 try something like this: [php:1:f49acaf7d6]<?php $conn = mysql_connect(\"localhost\",\"***\",\"***\"); mysql_select_db(\"*database_here*\", $conn); $result = mysql_query(\"SELECT * FROM `xdcc`\", $conn); while ($row=mysql_fetch_array($result)) { mysql_query(\"DELETE FROM `xdcc` WHERE `id`=\'\".$row[\'id\'].\"\'\", $conn); } mysql_close($conn); ?>[/php:1:f49acaf7d6] for a start it doesnt know which database to work with. also maybe the id\'s in the table dont start with 1 and end with however many records there are in that table. [php:1:f49acaf7d6]<?php $result = mysql_query(\"SELECT * FROM xdcc\", mysql_connect(\"localhost\",\"***\",\"***\")); $countDB = mysql_num_rows($result); echo $countDB.\" Rows <BR>\"; $tempno = \"1\"; while ($tempno <= $countDB){ $query = \"DELETE * FROM xdcc WHERE id = \'$tempno\'\"; $result = mysql_query($query); $tempno++; } ?>[/php:1:f49acaf7d6] and just to be a prick you should learn about for() http://php.net/for [php:1:f49acaf7d6]<?php for ($tempno=1; $tempno <= $countDB; $tempno++) { $query = \"DELETE * FROM xdcc WHERE id = \'$tempno\'\"; $result = mysql_query($query); } ?>[/php:1:f49acaf7d6] Link to comment https://forums.phpfreaks.com/topic/1023-why-doesnt-it-delete/#findComment-3482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.