php functions
Posted in php functions
2431
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
43
This Month
114
This Year
598

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
I believe that in order to better your knowledge base, it takes a lot of failing in order to succeed. I don't consider anything a failure as long as you get back up and you learn from your own mistakes.
Unknown
Random CSS Property

border-inline-start-width

The border-inline-start-width CSS property defines the width of the logical inline-start border of an element, which maps to a physical border width depending on the element's writing mode, directionality, and text orientation. It corresponds to the border-top-width, border-right-width, border-bottom-width, or border-left-width property depending on the values defined for writing-mode, direction, and text-orientation.
border-inline-start-width css reference