Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    return a sequence of records from a function

    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();
    }

  • #2
    New Coder
    Join Date
    Mar 2003
    Location
    Hong Kong
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ---> while ($row = $result->fetchRow())

    You fetch ALL the rows in the result set.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •