PHP: How to pass variable id

0

Result:

  

Notice: Undefined variable: cat in C: \ xampp \ htdocs \ DSagredo \ forums.php   on line 18

     

Notice: Undefined variable: cat in C: \ xampp \ htdocs \ DSagredo \ forums.php   on line 20

     

SELECT * FROM forums WHERE idcategory =

     

Fatal error: Call to a member function fetch_assoc () on boolean in   C: \ xampp \ htdocs \ DSagredo \ inc \ link.class.php on line 62

index.php

$obj = new DSagredo();

$categories = $obj->getCategories();

foreach ($categories as $category) 
{
    $category = $cat["idcategory"];

     echo $cat["category"]; 

    $foros = $obj->getForums($category);

}

link.class.php

function getForums($categoria)
{
    echo $sql = "SELECT * FROM forums WHERE idcategory =". $categoria;

    $res = $this->mysqli->query($sql);

    while($row = $res->fetch_assoc())
    {
        $data[] = $row;
    }

   /*if(isset($data)){
        return $data;
    }*/
    return $data;
}
    
asked by Diego Sagredo 22.09.2016 в 16:14
source

2 answers

2

change

$category = $cat["idcategory"];

for

$cat["idcategory"] = $category 
    
answered by 22.09.2016 / 16:26
source
0
  

Notice: Undefined variable: cat in C: \ xampp \ htdocs \ DSagredo \ forums.php   on line 18 Notice: Undefined variable: cat in   C: \ xampp \ htdocs \ DSagredo \ forums.php on line 20

You must declare a variable before using it.

    
answered by 22.09.2016 в 16:22