plugin function problem [solved]

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
pumuklee

plugin function problem [solved]

Post by pumuklee »

hi
i create a plugin function

i use it in the template like {contornr}

but the problem is that i want to use something like this

global $gCms;
global $db;
$db =& $gCms->GetDb();

$operation = "SELECT * FROM contornr WHERE sessionid = '".$locsid."'";
$execres = $db->Execute($operation);


if($execres->RecordCount()==0)

this recorcount function gives me always call a memeber function on a non-object

what im doing wrong?

thansk
Last edited by pumuklee on Thu Jan 25, 2007 7:59 pm, edited 1 time in total.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: plugin function problem

Post by Dee »

Odd, the code looks alright. Check the table and field name?
This code works fine here (nothing echoed at the end):

Code: Select all

global $gCms;
$db =& $gCms->getDb();
$locsid = 1;

$query = "SELECT * FROM cms_users WHERE user_id = '$locsid'';
$result =& $db->Execute($query);

if ($result->RecordCount() == 0)
echo 'no results';
Regards,
D
pumuklee

Re: plugin function problem

Post by pumuklee »

hi

i use it in this way
i create a file in plugins folder

function.contornr.php

and the function name is
function smarty_cms_function_contornr3($params, &$smarty)
{

global $gCms;
global $db;
$db = &$gCms->GetDb();

if($db)
{
//select rows which sessionid is = new sessionid
$operation = "SELECT * FROM contornr WHERE sessionid = '".$locsid."'";
$execres = $db->Execute($operation);

if($execres->RecordCount() == 0)//if not exist the new sessionid,insert new row
...

and in this way it gives me this call a memeber function on a non-object for recordcount

why?
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: plugin function problem

Post by Dee »

Ah, OK, I tried it as a UDT from the admin (which is much easier... but shouldn't make a difference)
This code saved as plugins/function.contornr3.php and called with {contornr3} works fine overhere:

Code: Select all

<?php
function smarty_cms_function_contornr3($params, &$smarty)
{
	global $gCms;
	global $db;
	$db =& $gCms->GetDb();
	$locsid = 1;

	$query = "SELECT * FROM cms_users WHERE user_id = '$locsid'";
	$result =& $db->Execute($query);

	if ($result->RecordCount() == 0)
	{
		echo 'no result';	
	} else {
		echo 'result';
	}
}
?>
Clearing the cache from the admin might help (under "Site Admin" -> "Global Settings").
pumuklee

Re: plugin function problem

Post by pumuklee »

thanks for the help
i made the mistake because i change the name of the table in db
and i forget to change it in plugin

sorry my mistake

but now i understand the plugins

so that i write soem words about plugins:
1. plugin file name must be something like this: function.thename.php
2. in file the function name which we want to call must be: smarty_cms_function_thename($params, &$smarty)
3. the error messages is a little bit poor so i say that it is useful to use echo for some data
    i use it print_r() for database returned data
4. for db u can use something like this
  global $gCms;
  global $db;
  $db = &$gCms->GetDb();
 
  if($db)
  {
      //select rows which sessionid is = new sessionid
      $operation = "SELECT * FROM contornr WHERE sessionid = '".$locsid."'";
      $execres = $db->Execute($operation);
     
      if($execres->RecordCount() == 0)

if the query has errors it returns memeber function on a non-object

i hope it is useful for someone
Locked

Return to “Modules/Add-Ons”