#Do a database query and return all rows of GET ID
$result=$mysqli->query("SELECT * FROM products WHERE product-id = '$id'");
while($row=$result->fetch_array())
{
$id = $row['product-id'];
$pagename = $row['product-name'];
$description = $row['product-description'];
$samples = $row['product-sample-designs'];
}
# free result set
mysqli_free_result($result);
}
#close connection
mysqli_close($mysqli);
If i remove WHERE product-id = '$id' # Result is no errors and first row is displayed.
As the code shows I get this error: “Fatal error: Call to a member function fetch_array() on a non-object”
I’m just trying to get all the data in a row where my GET id = the TABLE product-id. This process is much easier in MYSQL. Im new to this OOP style and I find it confusing. An explanation is greatly appreciated. ~THANKS!
If the column name contains hyphens, you need to enclose it by back-ticks.
But it is not a good idea of using hyphens in column/table names, use underscore
_would be better.