Jump to content

Show as random data from pages database (field 6)


ipbfuck

Recommended Posts

i try to explain again:

i've a database (quotes) i need to show, in template or block, field "content" from random id in this database.

 

instead to work with classic php and mysqli_conntect etc, can i do with ipb query? ^_^

Link to comment
Share on other sites

<!--SEE ON \system\Content\Item.php
/**
	 * Get items with permisison check
	 *
	 * @param	array		$where				Where clause
	 * @param	string		$order				MySQL ORDER BY clause (NULL to order by date)
	 * @param	int|array	$limit				Limit clause
	 * @param	string|NULL	$permissionKey		A key which has a value in the permission map (either of the container or of this class) matching a column ID in core_permission_index or NULL to ignore permissions
	 * @param	mixed		$includeHiddenItems	Include hidden items? NULL to detect if currently logged in member has permission, -1 to return public content only, TRUE to return unapproved content and FALSE to only return unapproved content the viewing member submitted
	 * @param	int			$queryFlags			Select bitwise flags
	 * @param	\IPS\Member	$member				The member (NULL to use currently logged in member)
	 * @param	bool		$joinContainer		If true, will join container data (set to TRUE if your $where clause depends on this data)
	 * @param	bool		$joinComments		If true, will join comment data (set to TRUE if your $where clause depends on this data)
	 * @param	bool		$joinReviews		If true, will join review data (set to TRUE if your $where clause depends on this data)
	 * @param	bool		$countOnly			If true will return the count
	 * @param	array|null	$joins				Additional arbitrary joins for the query
	 * @param	mixed		$skipPermission		If you are getting records from a specific container, pass the container to reduce the number of permission checks necessary or pass TRUE to skip conatiner-based permission. You must still specify this in the $where clause
	 * @param	bool		$joinTags			If true, will join the tags table
	 * @param	bool		$joinAuthor			If true, will join the members table for the author
	 * @param	bool		$joinLastCommenter	If true, will join the members table for the last commenter
	 * @param	bool		$showMovedLinks		If true, moved item links are included in the results
	 * @return	\IPS\Patterns\ActiveRecordIterator|int
	 */
	public static function getItemsWithPermission( $where=array(), $order=NULL, $limit=10, $permissionKey='read', $includeHiddenItems=\IPS\Content\Hideable::FILTER_AUTOMATIC, $queryFlags=0, \IPS\Member $member=NULL, $joinContainer=FALSE, $joinComments=FALSE, $joinReviews=FALSE, $countOnly=FALSE, $joins=NULL, $skipPermission=FALSE, $joinTags=TRUE, $joinAuthor=TRUE, $joinLastCommenter=TRUE, $showMovedLinks=FALSE )
REPLACE 4 with your database id-->
{{$quotes	= IPS\cms\Records4::getItemsWithPermission( array(),'RAND()',1 );}}

{{if !empty( $quotes ) }}
<h3 class='ipsWidget_title ipsType_reset'>Quotes</h3>
<div class='ipsPad_half ipsWidget_inner'>
	<ul class='ipsDataList ipsDataList_reducedSpacing'>
		{{foreach $quotes as $quote}}<!--SEE \applications\cms\sources\Records\Records.php apiOutput()-->
      {{$fields = $quote->fieldValues();}}
		<li class='ipsDataItem'>
			<div class='ipsDataItem_icon ipsPos_top'>
				{template="userPhoto" group="global" app="core" params="$quote->author(), 'tiny'"}
			</div>
			<div class='ipsDataItem_main'>
				{$quote->_title()}<br>
				<span class='ipsType_light ipsType_small'> {$quote->content()}</span>
			</div>
		</li>
		{{endforeach}}
	</ul>
</div>
{{endif}}

you could define $where = array("field_6<>''"); but i think there are prefix or suffix...

Link to comment
Share on other sites

Ok, sorry, fixed:

// Random quote in template from quotes database
$quotes = IPS\cms\Records3::getItemsWithPermission( array(),'RAND()',1 );
if(!empty( $quotes ))
foreach($quotes as $quote)
{
	$citazione = trim(strip_tags($quote->content()));
	if(strlen($citazione) > 120) {
		$citazione = trim(substr($citazione, 0, strrpos(mb_substr($citazione, 0, 114), ' '))." [...]");
	}
	$citazione = preg_replace( '/[^[:print:]]/', '',htmlentities($citazione)); // remove hidden chars
	echo "
	<p id='rss_sign'>
		<a href='".$quote->url()."' title='".\IPS\Member::loggedIn()->language()->addToStack( "author" ).": ".$quote->customFieldDisplayByKey("my_field_name", "raw")."'>
			<i class='fa fa-angle-double-left' aria-hidden='true'></i>".$citazione."<i class='fa fa-angle-double-right' aria-hidden='true'></i>
		</a>
	</p>";
}

demo: random quote in my website (jist at center, in every page)!

again, thank'u ^_^

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...