Need help converting a tiny script

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

You are missing the semi-colon on the line before.

2 Likes

And…

while ($row = mysql_fetch_array($result))

that function isn’t part of the language any more, you need to use the mysqli equivalent function.

3 Likes

Once the errors are cleared…

If you intend to create four separate tables the script should work, if not then open and close the table outside of the while loop.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.