user3046898
user3046898

Reputation:

post view rank php

Hi everyone i have one question for my dashboard rank panel.

the number of page views I want to sort from smallest to largest.

For example: a total of 100 times a page, but the other page ... 75-74-73-68-45-30 80 times.

I want to get older and smaller than the sequencing of numbers.

My php code is this. post_view is for how many people visit my post .

<?php include("connect.php");
$select_posts = "SELECT * FROM posts  LIMIT 0,9";
$run_posts = mysql_query($select_posts);
while($row=mysql_fetch_array($run_posts)){
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_date = date('d-m-y');
$post_author = $row['post_author'];
$post_view = $row['post_view'];
?>

<div class="div_name">
<div class="page-id"><?php echo $post_id; ?></div>
<div class="post_title"><?php echo $post_title; ?></div>
<div class="post-view"><?php echo $post_view; ?> </div>
</div>
<?php } ?>

Upvotes: 0

Views: 186

Answers (1)

kero
kero

Reputation: 10638

Use SQL's ORDER BY in the query:

SELECT * FROM posts ORDER BY post_view ASC LIMIT 0,9

If this field is not set to a numerical, you can use the following syntax

SELECT * FROM posts ORDER BY cast(post_view as int) ASC LIMIT 0,9

Upvotes: 2

Related Questions