Rectangle 27 0

php How to fix Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in?


Tier=1

plus check your sql by running in phpmyadmin to check whether it runs or not.

Note
Rectangle 27 0

php How to fix Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in?


$sql = "SELECT * FROM category WHERE tier='1' ORDER BY id ASC";
$fetch = mysql_fetch_assoc(mysql_query($sql)) or die(mysql_error());
while ($row = $fetch) {
    $p_id = $row["id"];
    $p_category_name = $row["category_name"];
    $mainMenu[''.$p_category_name.'']= $p_id;

    $sql_1 = "SELECT * FROM category WHERE tier='2' AND parent='$p_id' ORDER BY id ASC";
    $fetch_1 = mysql_fetch_assoc(mysql_query($sql_1)) or die(mysql_error());
    while ($row_1 = $fetch_1) {
        $c_id = $row_1["id"];
        $c_category_name = $row_1["category_name"];
        $subMenu[''.$p_category_name.''][''.$c_category_name.''] = 'product1.php';
    } 
}
$sql = mysql_query("SELECT * FROM category WHERE tier='1' ORDER BY id ASC") or die(mysql_error());
while($row[] = mysql_fetch_array($sql))

make sure all your queries are like this:

Note
Rectangle 27 0

php How to fix Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in?


SELECT * FROM category WHERE tier='2' and parent='$p_id' ORDER BY id ASC

You have an error in your query (forgot the and). Try this

Note
Rectangle 27 0

php How to fix Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in?


$sql_1=mysql_query("SELECT * FROM category WHERE tier='2' AND parent='$p_id' ORDER BY id ASC");

+1 ... and not PDO yet, PDO is not good for beginners. He must learn some mysql basics first :)

This means mysql_query failed to execute the query, and you should use mysql_error() to see the error message.

thanks for the link i'll go and check it out

Note
Rectangle 27 0

php How to fix Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in?


SELECT * FROM category WHERE tier='2' and parent='$p_id' ORDER BY id ASC

You have an error in your query (forgot the and). Try this

Note
Rectangle 27 0

php How to fix Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in?


$sql_1 = mysql_query(...) or trigger_error(mysql_error());
                         ^^^^^^^^^^^^^^^^^^^^^^--- bare mininum handling
$sql_1=mysql_query("SELECT * FROM category WHERE tier='2' parent='$p_id' ORDER BY id ASC");
                                                         ^-- missing ' AND '

If you had proper error handling in your code, you've have seen this:

Thanks for the quick responce. I am new to all this and i lack a lot of knowledge, i will try to keep that in my mind

You've got an SQL syntax error:

Note
Rectangle 27 0

php How to fix Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in?


$sql_1=mysql_query("SELECT * FROM category WHERE tier='2' AND parent='$p_id' ORDER BY id ASC");
$sql_1=mysql_query("SELECT * FROM category WHERE tier='2'  parent='$p_id' ORDER BY id ASC");

AND is missing from the query in the WHERE clause

Note