pro_php thread: mysql_fetch_array problems...please help.
Shiela spotted this too, but here it is again.
> $nforumid = explode(",",$nshowforums); $a = 0; $b = count($nforumid);
> while ($a < $b) {
> $extrawhere = "WHERE thread.forumid!='$nforumid[$i]'";
> ++$i;
> }
You're never incrementing $a, so it will ALWAYS be less than $b. Your
script will die when it exceeds the max_execution_time in php.ini.
However, no one addressed a bigger problem -- that if you fix your loop,
you're still going to have a bad script.
let's say your $nshowforums was set to something like this:
"1,2,6,16";
You'll generate the following text:
WHERE thread.forumid!='16'
You're not appending to the $extrawhere string, you're only assigning to
it -- that is, each loop iteration overwrites anything you wrote before it.
Now, if you were to fix THAT problem by appending the text, you'll still
need to introduce some whitespace (say, a newline at the end of the string),
or else you'll generate this:
WHERE thread.forumid!='1'WHERE thread.forumid!='2'WHERE
thread.forumid!='6'WHERE thread.forumid!='16'
Finally, even if THIS was fixed, you'd still generate bad SQL. The proper
syntax for a where clause is
WHERE <condition> [AND|OR <condition>...]
not
WHERE <condition> [WHERE <condition>...]
So what am I getting at? It looks to me like you want to generate this:
WHERE thread.forumid != '1' AND thread.forumid != '2' AND thread.forumid !
'6' AND thread.forumid != '16'
so what am I getting at? This, I guess:
foreach($nshowforums as $fid)
{
$where_clause .= "AND thread.forumid != '$fid'\n";
}
$query = mysql_query("SELECT post.postid, post.threadid,
post.username, post.dateline,
thread.forumid
FROM post, thread
WHERE $where_clause
ORDER BY dateline DESC LIMIT $numposts");
make sense?
nik