0

So I'm creating a webpage where I call into my database table blog_post. From there I'm accessing the top 10 most recent entries from the table ordered by their post_id. What I'm trying to do is make a unique link to the page /Blogpost.php. However when I execute this code all that displays is the header 'Recent Posts'. I know it has nothing to do with the connection because other php segments execute appropriately. However, Im struggling to get the links to just appear.

<div id="content">
        <div id="sidebarblog">
          <h1>Recent Posts</h1>
          <p id=blglst><?php
              $query = "SELECT * FROM (SELECT * FROM blog_post ORDER BY post_id DESC LIMIT 10) sub ORDER BY post_id DESC";
              $results = mysqli_query($db, $query);
              while ($row = mysql_fetch_array($results)){
                $title = $row['title'];
                $id=$row['post_id'];
                echo ("<a href='http://domain/Blogpost.php?id=" . $id . "'>" . $title . "</a><br />");
              }
            ?></p>
        </div>
    </div>
  • 1
    you are mixing mysql and mysqli. I don't think that this is a good thing. try a `var_dump(expressions and vars here)` to see the result of your php execution – chilly Sep 21 '17 at 19:10
  • "Not a good thing" is a polite way of saying "it won't work". Use `mysqli_` functions, the `mysql_` functions are deprecated in php 5 and **removed** in php 7. – Arjan Sep 21 '17 at 19:16
  • see [https://stackoverflow.com/a/31319761/6838730](https://stackoverflow.com/a/31319761/6838730) – Mathieu VIALES Sep 21 '17 at 19:17

1 Answers1

0

If nothing appears it most likely means that you do not enter the while part of your code.

You can try running the query directly against the database (using PhpMyAdmin for example) or you can try using var_dump() to debug your code and see if $result and $row contain data.

update : After looking it up, according to this answer and the documentation, mixing APIs isn't a very good idea ...

Mathieu VIALES
  • 4,526
  • 3
  • 31
  • 48