nbajpai nbajpai - 4 months ago 13
HTML Question

Want to display table row data as heading in html

I have database name "recipee" and table name "contents" in it. In "contents" there are two columns named "id" and "list". I want to display "list" as Heading in html. Table "contents" example

**id    list**
1 Malai Paneer
2 Kadhai Paneer


So, I want to display "Malai Paneer" and "Kadhai Paneer" as heading in html. I am using mysql, php and html.

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
//Open a new connection to the MySQL server
$mysqli = new mysqli('localhost','root','','recipee');

//Output any connection error
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$content_id = (int)$_GET['id'];

//MySqli Select Query
$results = $mysqli->query("SELECT id, list FROM contents where id = $content_id");
$id = ["id"];
$list = ["list"];



// Frees the memory associated with a result
$results->free();

// close connection
$mysqli->close();
?>
<h1> <?php echo $list?> </h1>
</body>
</html>


Expected output structure should be like:

***********************Kadhai Paneer(as main page heading)****************
* *
* *
* *
* *



Answer

use this

<html>
    <head>
        <title>Last 10 Results</title>
    </head>
    <body>
        <table border="1px solid black">

        <tbody>
        <tr>
        <?php
            $connect = mysqli_connect("localhost","root", "root","recipee");
            if (!$connect) {
                die(mysqli_error($connect));
            }

            $results = mysqli_query($connect,"SELECT list FROM contents");
            while($row = mysqli_fetch_array($results)) {
            ?>

                    <th><?php echo $row['list']?></th>



            <?php
            }
            ?>
            </tr>
            </tbody>
            </table>
    </body>
</html>