Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given

samxsamx texasMember Posts: 2

I am trying to select data from a MySQL table, but I get one of the following error messages:

mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given
in the line that contain the code "while($tab=mysqli_fetch_array($result)){"

and i've tried like one of the friends here advice me before running the query to use print_r wich is similar to var_dump so i get this error message :

select SQL_CALC_ FOUND_ROWS * FROM products limit0,5

before i get the message Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\green\functions\functions.php on line 401

This is my code:
if(isset($_GET['page'] )){
$currentPage=$_GET['page'];
}else{
$currentPage=1;
}

$currentPage=1;
$prevPage=$currentPage-1;
$nextPage=$currentPage+1;
$perPage= 5;
$start=($currentPage - 1)*$perPage;
global $con;
$requete="select SQL_CALC_ FOUND_ROWS* FROM products";
if(isset($_GET['cat'] )) { 
    $cat_id=$_GET['cat'];
    $requete.="WHERE product_cat='$cat_id' ";   
}

if(isset($_GET['brand'] )){  
    $brand_id=$_GET['brand'];
    $requete.="AND product_brand='$brand_id' ";
}

$requete.= "limit". $start.",".$perPage;
$result =mysqli_query($con, $requete);

if (!$requete) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
}

$requete2="select FOUND_ROWS() as rows";
$rows_result= mysqli_query($con, "select FOUND_ROWS() as rows");

if (!$requete2) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
}

$rows=mysqli_fetch_array($rows_result);
$totalRows=$rows['rows'];
$LastPage=ceil($totalRows / $perPage);

while($tab=mysqli_fetch_array($result)) {
    $pro_id = $tab['product_id'];
    $pro_cat = $tab['product_cat'];
    $pro_brand = $tab['product_brand'];
    $pro_title = $tab['product_title'];
    $pro_price = $tab['product_price'];
    $pro_image = $tab['product_image'];
    $pro_image_2 = $tab['product_image_2'];
    $product_date = $tab['product_date'];
Tagged:

Comments

  • B00B00 Member Posts: 77 ✭✭✭

    Do you even understand your SQL querry? Also there's a space in it which should not exist.

  • samxsamx texasMember Posts: 2

    can you tell me B00 where is the space that you're talking about please> @B00 said:

    Do you even understand your SQL querry? Also there's a space in it which should not exist.

  • B00B00 Member Posts: 77 ✭✭✭

    SQL_CALC_ FOUND_ROWS

    In front of F.

Sign In or Register to comment.