haqker Posted November 15, 2010 Share Posted November 15, 2010 I am looking to accomplish the following but have been hitting a brick wall: * User enters a single keyword into a text field, and conducts a search keyword search. * The results are pulled from the campusbooks.com API(API docs attached) * result are then output in <div> class and includes all the book details and its corresponding url./img etc I'm trying to simplify this process but I continue to receive syntax errors. A step by step practical explanation would do me justice! [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
haqker Posted November 15, 2010 Author Share Posted November 15, 2010 here's how the code looks thus far, courtesy of 'ignace' (thx) class CampusBooksAPIException extends Exception {} class CampusBooksGateway { private $apiKey; private $apiVersion = '11'; private $apiURL = 'http://api.campusbooks.com'; private $apiProtocol = 'rest'; function __construct($apiKey, $apiVersion = '11') { $this->apiKey = $apiKey; $this->apiVersion = $apiVersion; } function getPrices($isbn) { $simpleXML = $this->_query('prices', array('key' => $this->apiKey, 'isbn' => $isbn)); } function getBookInfo($isbn) { $simpleXML = $this->_query('bookinfo', array('key' => $this->apiKey, 'isbn' => $isbn)); } function searchByAuthor($author, $page, $imageWidth = 50, $imageHeight = 50) {} function searchByTitle($title, $page, $imageWidth = 50, $imageHeight = 50) {} function searchByKeyword($keyword, $page, $imageWidth = 50, $imageHeight = 50) {} function searchAll($input, $page, $imageWidth = 50, $imageHeight = 50) {} function getBookPrices($isbn) {} function getBuybackPrices($isbn) {} function getMerchantsAll() {} function getMerchantsBuy() {} function getMerchantsBuyback() {} private function _query($method, array $options) { $simpleXML = simplexml_load_file($this->_formatURL($method, $options)); if($simpleXML === false) throw new CampbusBooksAPIException('Campus Books API not available or invalid format.'); if($simpleXML->attributes()->status != 'ok') throw new CampbusBooksAPIException($simpleXML->errors->error); return $simpleXML; } private function _formatURL($method, array $options) { return $this->apiURL.'/'. $this->apiVersion.'/'. $this->apiProtocol.'/'. $method.'?'.http_build_query($options); } } --------- second part (courtesy of 'ignace'(thx) --------- try { $campusBooksAPI = new CampusBooksGateway('api-key-here'); $books = $campusBooksAPI->getPrices($_GET['ISBN']); foreach($books as $book) echo $book->getAuthor(), "<br>\r\n"; } catch (CampusBooksAPIException $e) { echo $e->getMessage(); } I need a practical explanation from start to end. I continue to receive 'syntax errors' Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted November 15, 2010 Share Posted November 15, 2010 if you post the errors, it might help us to help you fix them. Quote Link to comment Share on other sites More sharing options...
haqker Posted November 15, 2010 Author Share Posted November 15, 2010 Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/gradbayc/public_html/bookindex.php on line 7 Quote Link to comment Share on other sites More sharing options...
chintansshah Posted November 15, 2010 Share Posted November 15, 2010 is above code use for bookindex.php? Quote Link to comment Share on other sites More sharing options...
haqker Posted November 15, 2010 Author Share Posted November 15, 2010 yes Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.