PHP code that will display all links that are visited more than 20 times [closed]

StackOverflow https://stackoverflow.com/questions/19745520

  •  03-07-2022
  •  | 
  •  

Вопрос

I am looking for help in my project. I want to display all those links which are visited more then 20 times and also highest visited site will be at first.

I mean if google is visited through my website for 50 times then it will come to rank 1 like

1) [a link]Google[a]

Now second is Facebook which is visited for 30 times then it will come to

2) [a link]Facebook[a]

and if Facebook is viewed for 60 times then it will automatically come to first rank and Google will be at second.

For the rank, I've created column in database and it will always increase by +1 after every redirection to the website.

Please help me with PHP and MySQL code.

My table structure is:

ID, URL, CODE, DATE, VIEW, KEYWORD, DESCRIPTION

these are my codes :-

$a = "SELECT `url` FROM `url` ORDER BY `view` DESC";

$b = mysql_query($a);

$c = mysql_fetch_array($b);

print_r ($c);

and the result I am getting is

Array ( [0] => https://www.google.com [url] => https://www.google.com )

where I want

[0] =>google.com
[1] =>facebook.com
[1] =>linkedin.com

so any suggestions?

Это было полезно?

Решение

It is simple, SELECT views in DESC order, (Highest to Lowest)

SELECT * FROM table_name ORDER BY `VIEW` DESC


EDIT

$a = "SELECT * FROM table_name ORDER BY `view` DESC";
$b = mysql_query($a);
while($c = mysql_fetch_array($b))
{
    echo "<a href='$c[url]'>$c[url]</a> ". $c['view'] . " Views";
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top