Jump to content


Photo

why doesnt it delete <_>


  • Please log in to reply
4 replies to this topic

#1 Carl-Cox-

Carl-Cox-
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 September 2003 - 09:53 PM

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 :(
Dont you Forget It :)
[br]my first php site http://jub.jkub.com

#2 PHPcadet

PHPcadet
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationPlant City, Florida

Posted 16 September 2003 - 11:32 PM

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...e.html#TRUNCATE
If builders built buildings the way programmers write programs, then the first termite to come along would destroy civilization -- Anonymous

#3 DylanBlitz

DylanBlitz
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts
  • LocationOC Baby!

Posted 16 September 2003 - 11:41 PM

Just do

$query = \"DELETE FROM xdcc WHERE id = \'$tempno\'\";


don\'t need the *

#4 DylanBlitz

DylanBlitz
  • Members
  • PipPipPip
  • Advanced Member
  • 99 posts
  • LocationOC Baby!

Posted 16 September 2003 - 11:43 PM

One thing I don\'t understand, tempno is always going to be 1, and your deleting where the id is 1 every time?

#5 mydsmbr

mydsmbr
  • Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 September 2003 - 03:48 AM

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]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users