简体   繁体   中英

Export from MYSQL to HTML

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);
?>

您似乎期望使用关联数组,而不是常规(编号)数组,在这种情况下,请尝试:

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

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM