0

This is my first time using sp movie database on joomla. I am getting an error on spgenries, please help with this....

Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\Joomla_3.9.19\administrator\components\com_spmoviedb\fields\spgenries.php on line 25

JFormFieldSpgenries.php

<?php

/**
 * @package     SP Movie Database
 * @copyright   Copyright (C) 2010 - 2016 JoomShaper. All rights reserved.
 * @license     GNU General Public License version 2 or later.
 */

defined('_JEXEC') or die('Restricted access!');

jimport('joomla.form.formfield');

class JFormFieldSpgenries extends JFormField
{
    protected $type = 'Spgenries';

    public function getRepeatable()
    {
        return $this->getInput();
    }

    public function getInput()
    {
        $genre_ids = $this->value;

        if (isset($genre_ids) && count(json_decode($genre_ids))) {
            $genre_ids = implode(',', json_decode($genre_ids));
            $db = JFactory::getDbo();
            $query = $db->getQuery(true);
            $query->select(array('a.*'));
            $query->from($db->quoteName('#__spmoviedb_genres', 'a'));
            $query->where($db->quoteName('a.spmoviedb_genre_id') . " IN (" . $genre_ids . ")");
            $db->setQuery($query);
            $genries = $db->loadObjectList();

            $output = '';
            foreach ($genries as $key => $genre) {
                $output .= '<a href="index.php?option=com_spmoviedb&view=genre&id=' . $genre->spmoviedb_genre_id . '">' . $genre->title . '</a>' . ', ';
            }

            return rtrim(trim($output), ',');
        }

        return '....';
    }
}
5
  • Joomla Stack Exchange Please dump $genre_ids so that we can see what it is. Your query is only accessing one table, so there is no reason to nominate a table alias. – mickmackusa Jul 15 '20 at 13:02
  • You aren't using $key so there is no use in declaring it. I prefer to use http_build_query() to build url query strings. Instead of trailing every substring with a comma then mopping up the mess with trimming, create an array of links, then implode them with commas. – mickmackusa Jul 15 '20 at 13:08
  • After you solve the initial issue, then you'll find the next one. Implode will prefer an array, not an object. 3v4l.org/eZBFQ – mickmackusa Jul 15 '20 at 13:14
  • Ok thank you 👌👌 – Boorutotem lionation Jul 15 '20 at 14:24
  • I have not answered your issue. Please edit your question to provide the variable value. – mickmackusa Jul 15 '20 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy