0

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

4
Contributors
6
Replies
56
Views
3 Months
Discussion Span
Last Post by ryantroop
0

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.

0

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;
0

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

0
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;
        }
    }
    }
0

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.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.