0

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

Arash
  • 225
  • 1
  • 11

2 Answers2

1

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";
}
Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28
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";
}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
spirit
  • 3,265
  • 2
  • 14
  • 29