You'll want to declare a counter variable so we can keep track of each loop through and print it. $counter
is the variable I'm going to use in this example, and I declare it BEFORE the loop.
Replace your $post_numbers
variable with the $counter
variable, and INSIDE your loop, but at the END of it, we'll want to increment the $counter
variable by 1. $counter++
will increase after each loop through, so it will keep track of how many records there are.
$posts_sql = "SELECT id, added, title FROM posts ORDER BY added DESC LIMIT $offset, $post_limit";
$posts_res = mysqli_query($con, $posts_sql);
$counter = 1;
while($post = mysqli_fetch_assoc($posts_res)){
$post_id = $post["id"];
$post_added = $post["added"];
$post_title = ucwords($post["title"]);
$display_posts .= "
<b>$counter</b> ... <strong class='resultsLink'>$post_title</strong>";
$counter++;
};
^For every loop through, it'll increment your counter variable by one AFTER it posts the current number. Since it will only loop while there are results, that will effectively count for you so you can number your list.
EDIT
As suggested by CatalinB:
<b>sprintf("%02d",$counter)</b> ... <strong class=\"resultsLink\">$post_title</strong> to show 01 02 03
This will allow you to have the preceding 0 in front of single-digit numbers.