lukejd83 Posted November 16, 2010 Share Posted November 16, 2010 Hi all! I have racked my brain trying to figure this one out. I'm typically a smart cookie, but since I am new to php and mysql, I'm stumped. I'm just trying to program a Joomla search plugin that queries my HDFLV player database, so videos are searchable, but I keep getting an invalid "foreach(" command. It's supposed to be there to interpret the database query, right? I'll post my code here, can someone give me some insight? <?php /** * @version $Id: contacts.php 10381 2008-06-01 03:35:53Z pasamio $ * @package Joomla * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); $mainframe->registerEvent( 'onSearch', 'plgSearchhdflvplayer' ); $mainframe->registerEvent( 'onSearchAreas', 'plgSearchhdflvplayerAreas' ); JPlugin::loadLanguage( 'plg_search_hdflvplayer' ); /** * @return array An array of search areas */ function &plgSearchhdflvplayerAreas() { static $areas = array( 'hdflvplayer' => 'Videos' ); return $areas; } /** * Contacts Search method * * The sql must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav * @param string Target search string * @param string mathcing option, exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category */ function plgSearchhdflvplayer( $text, $phrase='', $ordering='', $areas=null ) { $db =& JFactory::getDBO(); $user =& JFactory::getUser(); if (is_array( $areas )) { if (!array_intersect( $areas, array_keys( plgSearchhdflvplayerAreas() ) )) { return array(); } } // load plugin params info $plugin =& JPluginHelper::getPlugin('search', 'hdflvplayer'); $pluginParams = new JParameter( $plugin->params ); $limit = $pluginParams->def( 'search_limit', 50 ); $text = trim( $text ); if ($text == '') { return array(); } $section = JText::_( 'hdflvplayer' ); switch ( $ordering ) { case 'oldest': $order = 'a.id ASC'; break; case 'popular': $order = 'a.times_viewed DESC'; break; case 'alpha': $order = 'a.title ASC'; break; case 'category': $order = 'b.title ASC, a.title ASC'; break; case 'newest': default: $order = 'a.id DESC'; } $text = $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false ); $query = 'SELECT a.title AS title, "" AS created,' . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END AS catslug, ' . ' CONCAT_WS( ", ", a.title, a.description ) AS text,' . ' CONCAT_WS( " / ", '.$db->Quote($section).', b.title ) AS section,' . ' "2" AS browsernav' . ' FROM #__hdflvplayerupload AS a' . ' INNER JOIN #__hdflvplayername AS b ON b.id = a.catid' . ' WHERE ( a.title LIKE '.$text . ' OR a.description LIKE '.$text.' )' . ' AND a.published = 1' . ' AND b.published = 1' . ' AND a.access <= '.(int) $user->get( 'aid' ) . ' AND b.access <= '.(int) $user->get( 'aid' ) . ' GROUP BY a.id' . ' ORDER BY '. $order ; $db->setQuery( $query, 0, $limit ); $rows = $db->loadObjectList(); foreach($rows as $key => $row) { $rows[$key]->href = '?pid='.$row->slug; } return $rows; } ANY help is more than what I got from HDFLV Player support. Thank you so much in advance! [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
lukejd83 Posted November 18, 2010 Author Share Posted November 18, 2010 I hate to bump my own topic, but can someone please assist? And if I'm not asking properly or doing some thing wrong, will someone tell me? Quote Link to comment Share on other sites More sharing options...
jim_keller Posted November 25, 2010 Share Posted November 25, 2010 what's the exact error? If it's related to the foreach, most likely it's because $rows isn't an array. You'll get an array if you try to pass something other than an array to a foreach loop. I would print your query to the browser, then try to run it directly in mySQL to see if the query is failing (which is one reason why $rows wouldn't be an array) Quote Link to comment Share on other sites More sharing options...
Ian Bothom Posted November 25, 2010 Share Posted November 25, 2010 Do post the error you are getting so we will sort it out if you didn't get the solution as you didn't post the error exactly. 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.