php functions
Posted in php functions
2452
10:52 pm, April 12, 2023
 

show views list function

list items by the view count

PHP

function show_views_list($max = 10, $ltype = "top", $ul_class = "", $crop_title_length = true, $interval_len = "1 day") {
	/* get_single_by_uid($field_name,$table_name,$uid,$uid_field_name = "uid") get_link($uid,$p = "view") */
	global $db;
	$out = "";
	if($ltype === "top") {
		$sql = "select * from views order by views desc limit $max";
	}
	if($ltype === "latest") {
		$sql = "select * from views order by insdate desc limit $max";
	}
	if($ltype === "time") {
		$sql = "select * from views where insdate >= date_sub(NOW(), interval $interval_len) order by insdate desc, views desc limit $max";
	}
	$result = $db->query($sql);
	while($row = mysqli_fetch_assoc($result)) {
		$uid = $row['uid'];
		$views = $row['views'];
		$views = restyle_number($views);
		$page_name = get_single_by_uid($field_name = "page_name",$table_name = "pages",$uid,$uid_field_name = "uid");
		
		if($crop_title_length == true) {
			if(strlen($page_name) >= 80 ) {
				$page_name = substr($page_name, 0, 80) . "[..]";
			}
		}
		$page_name_enc = htmlentities($page_name);


		$link = get_link($uid,$p = "view");
		if($page_name > "") {
			$out .= "<li><a href='$link' title='Views $views' ><span class='label'>$views</span> $page_name</a></li>";
		}
	}
	if($ul_class > "") {
		$ul_class = " class='$ul_class'";
	}
	$out = "
	<ul$ul_class>
		$out
	</ul>
	";
	return $out;
}

View Statistics
This Week
23
This Month
135
This Year
619

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
"Let us prepare our minds as if we'd come to the very end of life. Let us postpone nothing. Let us balance life's books each day ... The one who puts the finishing touches on their life each day is never short of time."
Seneca
Random CSS Property

src

The src CSS descriptor of the @font-face rule specifies the resource containing font data. It is required for the @font-face rule to be valid.
format() css reference