1

I want to output results from a MYSQL query into a HTML table using PHP. I am very new to this field and I read all the related questions but cant figure it out. I am sure the error is just a minor one.

Here is my PHP

$mysqli = new mysqli($db);

if($mysqli -> connect_error)
{
    die("Connect Error (".$mysqli -> connect_errno.") ".$mysqli -> connect_error);
}

$result = $mysqli->query("SELECT * FROM 'Users'");

$row = mysqli_fetch_row($result);

$mysqli->close();

And here is the snippet of the HTML table

<tr>
    <td><?php echo "$row[1]"; ?></td>
    <td>9</td>
    <td>48</td>
</tr>
2
  • What's your problem or question? Commented Mar 3, 2017 at 18:50
  • Oh, well, its not appearing on the webpage. So, the echo statement is not working. I dont know how. Commented Mar 5, 2017 at 13:30

1 Answer 1

1

you shouldn't put table name in quotes.

$result = $mysqli->query("SELECT * FROM Users");
echo '<table>';
while($row = mysqli_fetch_assoc($result)){
    echo '<tr>';
    // assuming table(User) have fields like id,name
    echo '<td>'.$row['id'].'</td>'; 
    echo '<td>'.$row['name'].'</td>'; //name is column name
    echo '</tr>';
  }
  echo '</table>';
  $mysqli->close();
Sign up to request clarification or add additional context in comments.

1 Comment

For a more flexible and robust answer, look here. stackoverflow.com/questions/42471993/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.