0

I am new to MYSQL and i am trying to export my database to html, and put the data into specific html tables. I have looked around the site, but i cant get my code to work, can someone help me, and tell me if this code looks right ?

<?php

    $con=mysqli_connect("xxx","xxx","xxx","xxx","xxx");
    // Check connection
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $result = mysqli_query($con,"SELECT * FROM xxx");

    while($row = mysqli_fetch_array($result)) 
    {
        <tr>
            <th bgcolor="#3281c6">" . $row["PO_nummer"]. "</th>
            <th bgcolor="#3281c6">" . $row["Varenummer"]. "</th>
            <th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th>
            <th bgcolor="#3281c6">" . $row["Antal"]. "</th>
    }

    mysqli_close($con);
?>
3
  • what is the issue (exception/incorrect UI rendering etc), highlighting will not force people here to assume your problems. Commented Mar 8, 2017 at 6:54
  • duplicate question: stackoverflow.com/questions/17902483/… Commented Mar 8, 2017 at 6:55
  • It's a good start to write youre html and php with quotes, or outside <?php tags. Check on how to do that: stackoverflow.com/questions/18140270/… Commented Mar 8, 2017 at 7:15

2 Answers 2

0

You seem to be expecting an associative array and not a regular (numbered) array, in this case try:

while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) { // code }

Sign up to request clarification or add additional context in comments.

Comments

0

Try and echo or print the html

echo "
<th bgcolor="#3281c6">" . $row["PO_nummer"]. "             </th>
<th bgcolor="#3281c6">" . $row["Varenummer"]. "</th>
<th bgcolor="#3281c6">" . $row["Produkt_beskrivelse_"]. "</th>
<th bgcolor="#3281c6">" . $row["Antal"]. "</th>";

And use single quotes here bgcolor='#3281c6'

Comments

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.