I was turned on to nstrees from another question, and have been working through the script. It was last updated in 2005 and relied on some stuff that has since apparently been deprecated like HTTP_POST_VARS
which I wasn't immediately familiar with since I've been doing PHP for only a little less than a year.
Anyways, the coding style seems weird to my rookie eyes, and I'd like a second opinion on what part of this function does:
// returns the first node that matches the '$whereclause'.
// The WHERE clause can optionally contain ORDER BY or LIMIT clauses too.
function nstGetNodeWhere ($thandle, $whereclause) {
$noderes['l'] = 0;
$noderes['r'] = 0;
$res = mysql_query("SELECT * FROM ".$thandle['table']." WHERE ".$whereclause);
if (!$res) { // problem area 1
_prtError();
} else {
if ($row = mysql_fetch_array($res)) { // problem area 2
$noderes['l'] = $row[$thandle['lvalname']];
$noderes['r'] = $row[$thandle['rvalname']];
}
}
return $noderes;
}
In the above code I marked the spots I'm not quite sure about as // problem area x
, everything else is the original script.
Regarding PA1, is that just a check on whether the query was successfully run?
And PA2, NetBeans gives me a warning "Possible accidental assignment, assignments in conditions should be avoided." ... so I promptly changed that from =
to ==
and of course broke the script, heh.
Thinking about it, I guess it's just another error check on $res
, this time to make sure that some data was actually returned?
Lastly, is this bizarre PHP or am I just too green to grok it?
Thanks dude(tte)s!