'How to convert mysql_result to mysqli result in this example [duplicate]
I understand how to fetch a result in mysqli, but how would this example be coded for mysqli?
for ($i = 0; $i < $num_rows; $i++) {
$uname = mysql_result($result, $i, "username");
$email = mysql_result($result, $i, "email");
echo "<tr><td>$uname</td><td>$email</td></tr>\n";
}
Thanks for taking a look
Solution 1:[1]
You can do like this:
while ($row = mysqli_fetch_assoc($result)) {
$uname = $row["username"];
$email = $row["email"];
echo "<tr><td>$uname</td><td>$email</td></tr>\n";
}
Solution 2:[2]
Assuming you've converted your other calls to return $result as a mysqli_result object, the most efficient way to do this would probably be
while ($row = $result->fetch_assoc())
{
echo "<tr><td>{$row['username']}</td><td>{$row['email']}</td></tr>\n";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Your Common Sense |
| Solution 2 | Darwin von Corax |
