Hi
I want to setup a WHERE Clause in my module. I am unsure of the Syntax. I have looked around at other modules but have had no joy in deciphering things.
I was wondering if there was a solid example to work from.
The module is based on the Template mnodule. I want the user to be able to select all inputs or by region.
Ie from user side if they click on the module form the main menu it gives option of All then region1 region2 and so forth.
Thanks
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- internetking created topic »password problem« 10:33 PM
- mesteele101 responded to »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 07:01 AM
- mazdev responded to »Pages 2.5.0 and updating - Page not found« 06:41 AM
- ehdwma created topic »Hide "Register new account" and change template to 3 col« 06:27 AM
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 01:29 AM
- mdee created topic »How to implement returnpage ?« 01:00 AM
- nestormateo responded to »Fillters in Clip« 24. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Help with SYNTAX for WHERE statement from User perspective
-
**unknown user**
- Rank: Softmore
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 395
when u say WHERE, i assume u mean when u grab data from the database.
in the example module, there is an API function called get($args). this gets the info for a particular item
Code
/**
* get a specific item
*
* @param $args['tid'] id of example item to get
* @return array item array, or false on failure
*/
function Example_userapi_get($args)
{
// Get arguments from argument array - all arguments to this function
// should be obtained from the $args array, getting them from other places
// such as the environment is not allowed, as that makes assumptions that
// will not hold in future versions of PostNuke
extract($args);
// Argument check - make sure that all required arguments are present, if
// not then set an appropriate error message and return
if (!isset($tid) || !is_numeric($tid)) {
pnSessionSetVar('errormsg', _MODARGSERROR);
return false;
}
// Get datbase setup - note that both pnDBGetConn() and pnDBGetTables()
// return arrays but we handle them differently. For pnDBGetConn() we
// currently just want the first item, which is the official database
// handle. For pnDBGetTables() we want to keep the entire tables array
// together for easy reference later on
$dbconn =& pnDBGetConn(true);
$pntable =& pnDBGetTables();
// It's good practice to name the table and column definitions you are
// getting - $table and $column don't cut it in more complex modules
$exampletable = $pntable['example'];
$examplecolumn = &$pntable['example_column'];
// Get item - the formatting here is not mandatory, but it does make the
// SQL statement relatively easy to read. Also, separating out the sql
// statement from the Execute() command allows for simpler debug operation
// if it is ever needed
$sql = "SELECT $examplecolumn[itemname],
$examplecolumn[number]
FROM $exampletable
WHERE $examplecolumn[tid] = '" . (int)pnVarPrepForStore($tid) ."'";
$result =& $dbconn->Execute($sql);
// Check for an error with the database code, and if so set an appropriate
// error message and return
if ($dbconn->ErrorNo() != 0) {
return false;
}
// Check for no rows found, and if so return
if ($result->EOF) {
return false;
}
// Obtain the item information from the result set
list($itemname, $number) = $result->fields;
// All successful database queries produce a result set, and that result
// set should be closed when it has been finished with
$result->Close();
// Security check - important to do this as early on as possible to avoid
// potential security holes or just too much wasted processing. Although
// this one is a bit late in the function it is as early as we can do it as
// this is the first time we have the relevant information
if (!pnSecAuthAction(0, 'Example::', "$itemname::$tid", ACCESS_READ)) {
return false;
}
// Create the item array
$item = array('tid' => $tid,
'itemname' => $itemname,
'number' => $number);
// Return the item array
return $item;
}
- Moderated by:
- Support
