0

I am implementing history.php as a controller and history.php as a template to display user's history. but it doesn't display anything. I made sure that history.php(controller) is readable -rw-r--r-- and history table works fine with any transaction.the history table includes(transaction,id,date/time,symbol,price,shares ) .i don't know why nothing is displayed. here's history.php(controller)

   <?php 


  // configuration
    require("../includes/config.php"); 


 $rows = query("SELECT* FROM history WHERE id = ?",$_SESSION["id"] );   

      if($rows == false)
     {
         apologize("there's no history"); 
     }

      render("history.php",["title" => "history","rows" => $rows);

  ?>


and here's history.php(template)

      <div>

          <table border = 2 >



          <?php

         print("<tr>");
         print("<th> TRANSACTION </th>");
         print("<th> date/time </th>");
         print("<th> SYMBOL </th>");
         print("<th> SHARES </th>");
         print("<th> PRICE PER SHARE </th>"); 
         print("</tr>"); 

     foreach ($rows as $position)
    {

         print("<tr>");
         print("<td>{$position["transaction"]}</td>");
         print("<td>{$position["date/time"]}</td>");
         print("<td>{$position["symbol"]}</td>");
         print("<td>{$position["shares"]}</td>");
         print("<td>{$position["price"]}</td>");
         print("</tr>");
    }

     ?>
         </table>
      </div>
    <div>
        <a href="logout.php">Log Out</a>
     </div>

  • when you say "nothing is displayed", do you mean literally nothing or just the table is missing? you could update your question with a screenshot of what appears in the history page! – Kareem Nov 21 '15 at 6:20
  • as a side note, php files don't need to be readable by the group nor everyone else. – Kareem Nov 21 '15 at 6:21
  • a blank page appears . nothing is displayed – kawegan Nov 21 '15 at 8:12
0

I forgot to close the bracket in the second argument in the function render

| improve this answer | |
0
  1. Not related to your problem but remember from the pset specs that $rows may be empty but that does not mean return value == false.
  2. You're on the right track, the reason your table isn't appearing on the template is because you enclosed your html within the php tag. Take it out, here's what your table should look like in html, you can play with the formatting as you like:

Transaction Date Symbol Shares Price

Your php code comes right after that, enclosed in php tag.

| improve this answer | |
  • actually [] == false is true in PHP! – Kareem Nov 21 '15 at 6:16
  • do you mean that I should remove all html tags and just leave the table tag with php code inside ? – kawegan Nov 21 '15 at 8:33
  • Sorry, hadn't realized that "<? php ?>" doesn't come out right, nor does the html code. Please see revised answer.It doesn't seem like html can be easily rendered as code, even if it does in the preview. So the answer to your question is your first table above should not be enclosed in the php tag, but in html "<table></table>" tags. You can also do away with the echo and enclose each of Transaction, Date, Symbol, etc. in "<th>, </th>" tags. Again, sorry for the bad formatting earlier. – ronga Nov 21 '15 at 13:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .