php functions
Posted in php functions
2591
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
162
This Month
274
This Year
758

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
1. Show your work to the world instead of keeping in your head💆. 2. Do the work consistently👌 3. Respect your work🥰 4. Don't postpone your work 5. Make mistakes 🔥🔥🔥
Unknown
Random CSS Property

aspect-ratio

The aspect-ratio CSS property sets a preferred aspect ratio for the box, which will be used in the calculation of auto sizes and some other layout functions.
aspect-ratio css reference