Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my error : mysql_fetch_assoc() expects parameter 1 to be resource, array given..


Please help me..i cant find any help from google..

my code:

PHP
<?php

        //print_r($categories);exit;
         $current_cat = null;

        
        while($row = mysql_fetch_assoc($categories))
        {
        //print_r($row);exit;
        if ($row["title"] != $current_cat)
        {
        $current_cat = $row["title"];
          echo $current_cat; // course category name
        }
        else
        {
          echo $row["course_title"]; // course name 
        }
        } ?>



array output is :(print_r($categories);exit;)

Array ( [0] => Array ( [category_id] => 2 [title] => Deck Courses [course_title] => Adaptive Steering ) [1] => Array ( [category_id] => 2 [title] => Deck Courses [course_title] => Test subject 2 ) [2] => Array ( [category_id] => 2 [title] => Deck Courses [course_title] => Test subject 4 ) [3] => Array ( [category_id] => 3 [title] => Engine Room Courses [course_title] => Test subject 3 ) )
Posted
Updated 21-Sep-13 0:41am
v2

What is the source of $row ? That would be ever so helpful in diagnosing your error.

mysql_fetch_assoc is expecting a rowset, which is the return value from a successful (SELECT) via mysql_query().

http://php.net/manual/en/function.mysql-fetch-assoc.php[^]
 
Share this answer
 
Try this :



PHP
<?php

         $current_cat = null;
         $data[]=null;

        while($row = mysql_fetch_assoc($categories))
        {
        $data[] = $row;
        }

        foreach($data as $item)
        {
          if ($item["title"] != $current_cat)
          {
           $current_cat = $item["title"];
           echo $current_cat;
          }
          else
          {
           echo $item["title"];
          }
        
        }

         ?>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900