For each retrieved row, add a Book_Item object

For each retrieved row, add a Book_Item object to the $bookShopContent array: $bookShopContent[] = new Book_Item($row[0], $row[1], $row[2], $row[3], $row[4]); } mysql_free_result($result); Return $bookShopContent: return new Function_Result(null, $bookShopContent); } The function getItem() returns the Book_Item object corresponding to item number $itemNo: function getItem($itemNo) { // Get DB Connection $functionResult = getDBConnection(); if ($functionResult->returnValue == null) { return $functionResult; } $link = $functionResult->returnValue; SELECT query to retrieve book information for item number $itemNo: $bookShopSelectQuery = “SELECT itemNo, itemType, price, title, author FROM BookShop WHERE itemNo=’” . $itemNo . “‘”; Execute the query: if (!($result = mysql_query($bookShopSelectQuery, $link))) { return new Function_Result(”Internal Error: Could not execute sql query “, null); } Fetch the row from the result of the query: $row = mysql_fetch_array($result, MYSQL_NUM); if ($row == null) { return new Function_Result(null, null); } else { Create a Book_Item object for the retrieved row: $item = new Book_Item($row[0], $row[1], $row[2], $row[3], $row[4]); Page 565

Hint: This post is supported by Gama web hosting php mysql provider

Comments are closed.