Support Forums

get_extra_field by internal name

This is a discussion on get_extra_field by internal name within the Customizations forums, part of the Developer Forums category; I wrote a small plugin to perform the get_extra_field function using a specified internal name instead of the id. Not ...


Go Back   68 Classifieds Forums > Developer Forums > Customizations

Reply
 
Thread Tools Display Modes
Old 07-15-2010, 11:02 AM   #1
Junior Member
 
Join Date: Jul 2010
Posts: 1
Rep Power: 0
jimdoescode is on a distinguished road
Default get_extra_field by internal name

I wrote a small plugin to perform the get_extra_field function using a specified internal name instead of the id. Not sure if anyone would find this useful I was just having trouble remembering the extra field ids.

Code:
<?php
/**
Call like {get_extra_field_by_name id=entry.id name='internal-name'} 
**/
function smarty_function_get_extra_field_by_name($params, &$smarty)
{
	global $db,$modules;
	$id = isset($params['id']) ? (int)$params['id'] : 0;
	$name = isset($params['name']) ? $params['name'] : '';
	if($id > 0)
	{
		$sql = "SELECT v.sValue AS value FROM ".PREFIX."fields n, ".PREFIX."products_fields v WHERE v.fID = n.fID AND v.pID = {$id} AND n.fInternal = '{$name}'";
		$result = $db->query($sql);
		//If everything checked out
		$value = false;
		if(!$result->isError() && $result->size() > 0)
		{
			$dbvals = $result->fetch();
			$value = $dbvals['value'];
		}
		$result->freeResult();
		return $value; 
	}
}	
?>
Copy the code above into a file called function.get_extra_field_by_name.php and place it into your plugins folder. You call is using the same syntax you would with the regular get_extra_field but instead of specifying fID you would set name equal to the internal name of your field.

There is a bit more sql processing that has to be done, but it will most likely be negligible unless you are displaying thousands of ads on a single page (in which case this plugin would be the least of your worries)

Feel free the do whatever you want with this code.
jimdoescode is offline   Reply With Quote
Old 07-15-2010, 11:52 AM   #2
All Hands On Deck
 
 
Join Date: Mar 2008
Posts: 3,342
Rep Power: 84
seymourjames is a jewel in the rough
Default

A nice contribution and thanks for sharing.
__________________
"The fool doth think he is wise, but the wise man knows himself to be a fool.".

TemplateCodes.com for 68C, Version 4 Templates & Modules
Get the Best U.S Hosting, Best U.K Hosting
seymourjames is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Google showing internal links calaf6 Templates, HTML, CSS, and Design Help 3 02-22-2008 05:57 PM
Adding Internal Navigation Menu sleepy Templates, HTML, CSS, and Design Help 1 04-13-2006 09:12 AM


All times are GMT -4. The time now is 10:17 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0