hi im working on a php script and i have come across the following error does anyone have a ideal what can cause this the error is:
PHP Warning: count(): Parameter must be an array or an object that implements Countable in /home/letsswin/public_html/dating_V1/dating/admincp/educations.php on line 74.

the code where it comes from is :

<?php
        if(isset($error) && !empty($error))
            echo '<p style="margin:0px; padding:5px 20px"><font color="#FF0000"><small><i>'.$error.'</i></small></font></p>';
        $list = getListed(array('EducationID' => 'Id', 'L1Education' => 'L1Value', 'L2Education' => 'L2Value'), array($table_prefix.'educations', 'Id'));
        if(count($list)>0){
        ?>

any help would be much appreciated ty jan x

Recommended Answers

All 6 Replies

what does this do?

$list = getListed(array('EducationID' => 'Id', 'L1Education' => 'L1Value', 'L2Education' => 'L2Value'), array($table_prefix.'educations', 'Id'));

if the answer isnt "it RETURNS an array" then you found your problem.

it works along with this section on form

<tr>
                        <td width="30%" align="right" valign="top">Educations : </td>
                        <td width="70%" align="left"><select name="slEducation">
                            <?php
                            $sel = isset($_POST['slEducation'])?$_POST['slEducation']:$list['EducationID'];
                            $sql = 'select EducationID as Id, '.$_SESSION['lang'].'Education as LName from '.$table_prefix.'educations order by TopSorted desc, LName asc';
                            dropdownlist($sql, $sel);
                            ?>
                        </select></td>
                    </tr>

then heres the database table for it

CREATE TABLE `dt_educations` (
  `EducationID` smallint(5) UNSIGNED NOT NULL,
  `L1Education` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  `L2Education` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
  `L3Education` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  `L4Education` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  `TopSorted` smallint(6) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Show your function getListed

getlisted function must return array either first or second you passing, or anything you process convert it to array and return it in getlisted

if(!function_exists('getListed')){
    function getListed($field=array(), $table=array()){
        global $link;
        $sel = '';
        foreach($field as $field => $val)
            $sel .= $field.' as '.$val.', ';
        $sql = "select ".substr($sel, 0, -2)." from ".$table[0]." order by ".$table[1]." desc";
        if(!empty($link)) {
        $query = mysqli_query($link,$sql);
        if(!$query)
            return false;
        else return $query;
        }
    }
    }

So, if you return false you don't have an array - hence your error. You should first check to see if you have an result before you run count.

You can do that with something like if ($list && count($list) > 0) -- and the first clause will short circuit and not try to run the count.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.