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();

Never worked with mysqli before please help strait up my code so it works.

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


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

echo '<table align="center" width="70%"><tr>';  
$count = 0;  
$rowCount = 0; 
while($row = mysqli_fetch_array($result))  
{  
$count++; 
$rowCount++; 

echo "<td><a href='http://" . $row['GALLERYURL'] . "'><img src='" . $row['THUMBURL'] . "'   width='120' height='160'/></a></td>";  
if($count%8===0) 
{ 
    echo '</tr>'; 

    if($rowCount%5===0) 
    { 
        echo '</table><br/><br/>Adds Here<br/><br/><table align="center" width="70%"><tr>'; 
        $rowCount = 0; 
    } 
   } 
} 
echo ' </tr></table>';  

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

 ?> 

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.

链接地址: http://www.djcxy.com/p/69224.html

上一篇: 错误:mysql

下一篇: mysqli问题得到连接