search feature old version cms builder 1.12
2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 14, 2013 (RSS)
By biorn - March 13, 2013
we have a site using cms 1.12. the site is working fine and no issues. it is very customized and no need for any upgrades.
we are going to add a search feature and so far that works fine for one list (or sql tables), but not multiple on the same page.
we have the following code on the result page:
<?php
require_once "D:/Inetpub/3dscanningtechnologies/cms3d/lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'industrynews'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = 'title'; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = 'industrynewsPage.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = '17'; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'featured_article DESC, date DESC, title'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
$options['pageNum'] = ''; // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
$options['where'] = ''; // (ADVANCED) Additional MySQL WHERE conditions. Example: 'fieldname = "value"'
$options['useSeoUrls'] = ''; // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers)
list($listRows, $listDetails) = getListRows($options);
?>
this works all fine and no issues and it searches just fine.
However, we have several tables (not only the "industrynews"). how do we include the search to display results from multiple tables?
thanks,
biorn
By gregThomas - March 14, 2013
Hi Biorn,
The best option is to use multiple getListRows functions and combine them into a single array to display the results, something like this would work:
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'industrynews'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = 'title'; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = 'industrynewsPage.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = '17'; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'featured_article DESC, date DESC, title'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
$options['pageNum'] = ''; // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
$options['where'] = ''; // (ADVANCED) Additional MySQL WHERE conditions. Example: 'fieldname = "value"'
$options['useSeoUrls'] = ''; // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers)
list($pages, $listDetails) = getListRows($options);
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'blog'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = 'title'; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = 'blog.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = '17'; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'featured_article DESC, date DESC, title'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
$options['pageNum'] = ''; // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
$options['where'] = ''; // (ADVANCED) Additional MySQL WHERE conditions. Example: 'fieldname = "value"'
$options['useSeoUrls'] = ''; // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers)
list($blogs, $listDetails) = getListRows($options);
$searchResults = array();
$i= 0;
foreach($blogs as $blog){
$searchResults[$i]['title'] = $blog['title'];
$searchResults[$i]['desc'] = $blog['content'];
$searchResults[$i]['link'] = '/blog.php?num='.$blog['num'];
$i++;
}
foreach($pages as $page){
$searchResults[$i]['title'] = $page['title'];
$searchResults[$i]['desc'] = $page['content'];
$searchResults[$i]['link'] = '/page.php?num='.$page['num'];
$i++;
}
?>
<ul>
<?php foreach($searchResults as $result): ?>
<li><b><a href="<?php echo $result['link']; ?>" ><?php echo $result['title']; ?></a></b><?php echo $result['desc']; ?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
This is just example code, so you'll need to make a few changes to get it working with your site.
So I've searched two tables using the getListRows function, then I'm cycling through the results of both and adding the fields I want to use to the search Results array. Then I display its content in a html list.
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com