// This is a generic function which returns the results // of a query in list form, so they can be used in place // of nested queries until it is implemented in MySQL // If there are no values, it returns the string // "Empty Nested Set" by default.
function getnestedvals($field, $table, $comparefield, $key) { $nestedquery = "SELECT $field FROM $table WHERE $comparefield = '$key'"; $nestedresult = mysql_query($nestedquery) or die("MySQL Error: " . mysql_error() . " $nestedquery"); if (mysql_num_rows($nestedresult) == 0) { return "Empty Nested Set"; } else { $row = mysql_fetch_array($nestedresult); $nestedvals = $row[$field]; while ($row = mysql_fetch_array($nestedresult)) { $nestedvals = $nestedvals . ", $nestedvals"; } return $nestedvals; } // end of else numrows > 0 } // end of getnestedvals() An piece of code that uses an example call for this using PHP4 to get the number of tickets owned by people in a certain department was: $deptname = genericget($deptid, deptid, deptname, department); $querytickets = "SELECT * from ticket WHERE owner IN (" . getnestedvals(id, user, dept_id, $deptid) . ")"; $result = mysql_query($querytickets) or die("MySQL Error: " . mysql_error() . " $querytickets."); $numtickets = mysql_num_rows($result); echo "There are $numtickets tickets owned by $deptname ."; --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php