someCoder
someCoder

Reputation: 185

Fill HTML table with PHP

I'm going nuts over this table. In this page I'm supposed to show all the orders made by an user and the code is basically the same I used in another page, but the the PHP code won't freaking fill the HTML table.

<html>
<body>
    <h1>Your orders</h1>
    <table width = "550px" height = "300px" border="2" >
    <tr bgcolor="#5f9ea0">
     <td>Videogame</td>
     <td>Price</td>
     <td>Payment</td>
     <td>Date</td>
    <td>Delete order</td>
    <td>Game received</td>
  </tr>

  <?php
     $conn=pg_connect('dbname=project user=project password=project');
     $user=$_SESSION['Userdata']['username'];
     $query="SELECT o.IDOrder, v.Title, o.price, o.paymenttype, o.date FROM negozio_vg.order o INNER JOIN negozio_vg.videogame v ON o.videogame=vIDVideogame WHERE username='$user' ORDER BY o.date";
     $result=pg_query($conn,$query);
     while ($rows=pg_fetch_assoc($result)) {
        printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a href='orderhandler.php'>Delete</a></td><td><a href='orderhandler.php'>Confirm</a></td></tr>",  $rows['title'], $rows['price'],$rows['paymenttype'],$rows['date']);
     }
     ?>
 </table>
  <form action="homeUser.php">
     <input type="submit" value="Ritorna al menu">
  </form>
 </body>
</html>

I'm seriously going nuts, because, as I said, I used the same code in another page. Even worse, the query actually works, and so does the while loop (I tried using an echo instead of a printf and it printed the whole order list) Any suggestions?

Upvotes: 1

Views: 2907

Answers (1)

Jeffwa
Jeffwa

Reputation: 1143

You have 5 placeholders and provide only 4 values. It's possible the error is either suppressed or it's not displaying in the HTML. Regardless, either remove an %s or add another substitution value $rows['some_column_name']

Upvotes: 2

Related Questions