Saturday 28 January 2017

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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...