General Community > Scripting Help
mysql_fetch_array question...
Aquilo:
--- Quote ---<?php
$systempath = "/home/USER/public_html";
include ("$systempath/file.inc");
$request = mysql_query("
select page, post
from $usertable") or die("Failed: " . mysql_error());
while ( $acc = mysql_fetch_array($request) )
{
if($acc["page"] && $acc["post"] == '0')
{
echo $acc['page'].' equals '.$acc['post'] ."<br />\n";
$request = mysql_query("
DELETE FROM `table`
WHERE 1 AND `post` = '0' AND `page` = '".$acc[page]."'") or die("something went wrong with ".$acc["page"].": " . mysql_error());
unlink($systempath."/". $acc["page"] .".php") or die("Unable to remove: ".$acc["page"]);
echo $acc["page"] . ' is gone!<br />'."\n";
}
}
?>
--- End quote ---
the job is none all I had to do use keep hitting refresh and there where around 100 account to remove but what would cause this while loop to loop once and fail??
Aquilo
Joshua Dickerson:
a.) what did it say when it failed? probably couldn't get the table because $usertable isn't defined
b.) don't use fetch_array, use fetch_assoc
c.) use $var['bar'] instead of "bar"
d.) don't use WHERE 1. Just remove the 1.
Iridium:
Did you actually mean to do this:
--- Code: ---if($acc["page"] && $acc["post"] == '0')
--- End code ---
or where you in fact wanting to do this:
--- Code: ---if($acc["page"] == '0' && $acc["post"] == '0')
--- End code ---
Aquilo:
--- Quote from: Iridium on September 04, 2003, 07:16:58 PM ---Did you actually mean to do this:
--- Code: ---if($acc["page"] && $acc["post"] == '0')
--- End code ---
or where you in fact wanting to do this:
--- Code: ---if($acc["page"] == '0' && $acc["post"] == '0')
--- End code ---
--- End quote ---
no It's right!
if(isset($acc["page"]) && $acc["post"] == '0')
I was testing to make shure the page name is right becouse I was deleting a file with that name and then removing the account from mySQL.
--- Quote from: groundup on September 02, 2003, 12:36:00 PM ---a.) what did it say when it failed? probably couldn't get the table because $usertable isn't defined
b.) don't use fetch_array, use fetch_assoc
c.) use $var['bar'] instead of "bar"
d.) don't use WHERE 1. Just remove the 1.
--- End quote ---
it said something like mysql_fetch_array was an invalid resource or something.
will fetch_assoc work the some way?
Joshua Dickerson:
usually means there were no result.. do EXPLAIN SELECT {query} to figure out if there were any rows and if there was a problem.
Navigation
[0] Message Index
[#] Next page
Go to full version