Creating the Main Pages of a PEAR CMS - Run the Query
(Page 4 of 4 )
Once we’ve created the query, we now have to run it. DB uses MySQL equivalent (mysql_query()) of $db->query() to run the query. The result of this query is stored in a variable called $res:
$res = $db->query($sql);
We test to see if any records have been returned, and then call the while loop to retrieve the records:
if($res){
while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
?>
The code then builds rows and columns as appropriate to display the information. Each row in the table will display the title of the article and the name of the author who wrote the article. The title of the article provides a link to the view page that allows you to view an article in full:
The link in the title of the article has a query string attached to it. This query string will send a story ID or sid to the view page, which then uses that id to retrieve the appropriate story:
In the next article we will delve more deeply into the page that allows us to view an article in full. Be sure to check back next week.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.