Need help converting a tiny script from PHP5 to 7

A

Anonymous

Guest
I've been trying to convert this little script but have gotten stumped (created it mostly from examples)
<?php

$mysqli = new mysqli("localhost","myname","mypwd","thedb");

if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}

//mysqli_select_db("mytable", $mysqli);

//$result = mysqli_query("SELECT * FROM blog ORDER BY id DESC LIMIT 4");

$result = $mysqli->query("SELECT * FROM blog ORDER BY id LIMIT 4")

//echo '<table class='blog'>;

while ($row = mysql_fetch_array($result))
{
echo "<table class='blog'>";
echo "<tr>";
echo "<td class='date'><hr>" . $row['date'] . "</td>";
echo "<tr><td class='item'>" . $row['item'] . "</td>";
echo "</tr>";
echo "</table>";
}

mysqli_close($mysqli);
?>

I have it working down to the WHILE statement. The server log says there is a syntax error in that line. The script worked just fine in PHP5 and displayed my blog entries on my private home page. I know this should be easy (and probably is for most of you) but I can't find an example that works for me. Thanks
 
While I don't use mysql(i) istead I use PDO (Which I recommend) shouldn't the following line be?

Code:
while($row = mysqli_fetch_assoc($result))

or
Code:
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))

instead of
Code:
while ($row = mysql_fetch_array($result))
 
Got it to work! Thanks for your suggestions, Strider.
 
Back
Top