...

View Full Version : return a sequence of records from a function



kenny873
03-12-2003, 02:27 AM
if I want to write a function with a given Main_cat_id parameter and it will return its sub_cat_id, total num of topic, moderator...how can I return a list of records in the function....i wrote the function and it only gave the last record:

function chooseCAT($catID){
$db = getDBPConn();
$sql = "select cat_id, parent_cat_id, cat_name,priority,tot_topics,moderator,banner_code,rec_cr_date,last_upd_date
from game_forum_category where parent_cat_id=$catID order by priority";

$result = $db->query($sql);
if (DB::isError($result = $db->query($sql))){
die (DB::errorMessage($result));
}
if ($result->numRows() > 0){
while ($row = $result->fetchRow()) {
$cat_id = $row[0];
$parent_cat_id = $row[1];
$cat_name = $row[2];
$priority = $row[3];
$tot_topics = $row[4];
$moderator = $row[5];
$banner_code = $row[6];
$rec_cr_date = $row[7];
$last_upd_date = $row[8];
return array($cat_id,$parent_cat_id,$cat_name,$priority,$tot_topics,$moderator,$banner_code,$rec_cr_date,la st_upd_date);
}
} else {
return false;
exit;
}
$result->free();
$db->disconnect();
}

hkucsis
03-12-2003, 05:27 AM
---> while ($row = $result->fetchRow())

You fetch ALL the rows in the result set.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum