Tuesday, July 17, 2018

php - mysqli issue getting connected



I'm trying to get connect to my data base and having issues with it all.



Im getting this error on my while statement while($row = mysqli_fetch_array($result))




Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given





How do I fix that?



and this error on line 56




Fatal error: Call to a member function close() on a non-object
$result->close();





$mysqli = new mysqli("hostedresource.com", "UserName", "pass", "database");


if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
if ($result = $mysqli->query("SELECT * FROM AllGallerys order by RAND() limit 200'")) {
}


echo '';
$count = 0;
$rowCount = 0;
while($row = mysqli_fetch_array($result))
{
$count++;
$rowCount++;

echo "";
if($count%8===0)

{
echo '';

if($rowCount%5===0)
{
echo '


Adds Here

';
$rowCount = 0;
}
}
}

echo '
';

$result->close();
$mysqli->close();

?>

Answer



You have a typo in your sql statement:




"SELECT * FROM AllGallerys order by RAND() limit 200'"
^ here


Apart from that the construction is a bit strange, you should at least add an else section in case the query fails.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...