|
You are here: Home / Documentation / Database Programming in Sitellite |
Database Programming in SitelliteA Simple Example<?php
echo template_simple (
'<h1>You have selected story the story named "{title}"</h1>',
db_single (
'select * from sitellite_news where id = ?',
$parameters['id']
)
);
?>
As you can see, there is no error handling here yet. However, this example illustrates the very concise nature of the Sitellite Database API. Let's insert error handling into it and break it up into multiple lines. <?php
$result = db_single (
'select * from sitellite_news where id = ?',
$parameters['id']
);
if (! $result) {
echo db_error ();
return;
}
echo template_simple (
'<h1>You have selected story the story named "{title}"</h1>',
$result
);
?>
This example outlines a few features of the Sitellite Database API, namely:
A More Interesting ExampleLet's look at another example: <?php
echo template_simple (
'<ul>{loop obj}
<li>
<a href="{site/prefix}/index/tutorials-story-action/story.{loop/id}">
{loop/title}
</a>
</li>
{end loop}</ul>',
db_fetch_array (
'select id, title
from sitellite_news
order by date desc
limit 10'
)
);
?>
Save this to a file, say inc/app/example/boxes/headlines/index.php. Then call it in your browser via http://www.yourWebSite.com/index/example-headlines-action. You can see from the example that it will display the ten most recent news headlines. Next, log into Sitellite and create a new sidebar by clicking on the "+" icon at the top of the left or right columns in the example site. Leave the body blank but enter an ID (say "example_headlines") and a Title (say "Latest Articles"), but click on the "Properties" tab and in the "Alias of (a box name)" field enter "example/headlines". Next, click on the "State" tab and set the Status to "Approved" and the Access Level to "Public" (I'm assuming you're not learning on a LIVE web site, by the way ;)). Click the "Create" button at the bottom of the form. You will now see your headline action inserted into the sidebar of your web site, seamlessly integrated into the existing web site. Page 1: Rationale |
|
Copyright © 2008, SIMIAN systems Inc. All rights reserved. Privacy policy Some of the icons on this site were created by the Gnome Project. |