Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aeltaib's avatar

Show data from database to table in html & php classic

Hi,

And I'm so sorry guys I'm new in php, but & can't show the data in data base, please need advise. I can't know where's the issue exactly. I wanted to post this question on stackoverflow.com, but there's an issue to post it, & I need answer urgent please about this question

<html>
<head>
    <title>Admin Page</title>

    <style>
        table{
            font-family: arial,sans-serif;
            border-collapse: collapse;
            width: 100%;
        }

        td,th{
            border: 1px solid #dddddd;
            text-align: left;
            padding: 8px;
        }

        tr:nth-child(even){
            background-color: #dddddd;
        }

    </style>
    </head>
    <body>
    
    <center><u><h1>Admin Tickets</h1></u></center>
    <center>
    <input type="text" name="text">
    <input type="button" value="Search ticket#"></br></br>
    </center>
    
    <table>
        <th>Ticket NO.</th>
        <th>Phone</th>
        <th>Subject</th>
        <th>Description</th>
        <th>Status</th>
        <th>Created Date</th>
        <th>Assign to</th>
        <th>Closed Date</th>
        <th> </th>        
        
        <tr>
                
            <td><label for="ticketID" value='<?php echo $row['phone']; ?>'></td>
            <td><label for="phone"><?php echo $row['phone']; ?></td>
            <td><label for="subject"><?php echo $row['subject']; ?></td>
            <td><label for="descreption"><?php echo $row['descreption']; ?></td>
            <td>
            <select>
            <option value="open">Open</option>
            <option value="hold">On hold</option>
            <option value="resolved">Resolved</option>
            <option value="closed">Close</option>
            <?php echo $row['status']; ?>
            </select>
            </td>
            <!--<td><input type="text" name="status"><?php echo $row['status']; ?></td>-->
            <td><label for="createdDate"><?php echo $row['createdDate']; ?></td>
            <td>
            <select>
            <option value="empty"> </option>
            <option value="HD">Help Desk</option>
            <option value="SA">System Admin</option>
            <option value="voice">Voice</option>
            <option value="noc">NOC</option>
            <?php echo $row['assignedTo']; ?>
            </select>
            </td>
            <td><label for="closed"><?php echo $row['closedDate']; ?></td>
            <td><center><input type="button" value="OK"></center></td>
        </tr>

        
        </table>

    <?php

    //include('connect.php');
    $id=$_GET['id'];
    
    $db=mysqli_connect('localhost','root','','task') or die('Error connecting to MySQL Server.');

    
    $query="SELECT tickets.ticketID,tickets.phone,tickets.subject,tickets.descreption,details.status,details.assignedTo FROM tickets,details WHERE tickets.ticketID=details.ticketID"; 
    
    
    mysqli_query($db,$query) or die('Error querying database.');

    $result=mysqli_query($db,$query);
    $row=mysqli_fetch_array($result);

    myqli_close($db);


    ?>

</body>
</html>

-so I need to show the data from DB & make the page save on the table.

0 likes
5 replies
mikerovers's avatar

You could try to put the php code that pulls the data from the database on top of the table as $row is not defined when it is accessed.

Could you var_dump() of dd() the result of the query?, so we can see of the result is correct.

1 like
aeltaib's avatar

@mikerovers may give me the real example as shown above, because I did it before & no way.

mikerovers's avatar

You are calling echo $row['status']; before $row=mysqli_fetch_array($result);.

My guess is that $row is not set yet when you echo the data.

Another problem could be that the $row is set wrong. You can show us the result of var_dump($row); or dd($row); after setting $row. That way you can check if $row is filled the way it if supposed to.

1 like
mikerovers's avatar

Yea, I guess because it has no data. Could you post the outcome of var_dump($row) or dd($row)?

Please or to participate in this conversation.