Can I use sc_lookup in a library?

Hi,

I trying to put commonly used code into a reusable library. This includes queries to get and correctly format addresses. I’m moving the working code from the onLoad event into a library.

When pulling in the library code, the generator is copying the code directly instead of converting the macro and globals. I tried sc_include instead of using the library, but it did not seem to make any difference.

$sql=‘select col1, col2, col3 from myTable’;
sc_lookup(rs, $sql);
$res=’’;
if (isset({rs[0][0]})) {
$res.={rs[0][1]}; // col 1

}

Any ideas on how to get this working? I have asked which macros work in libraries and I have been told most should.

Many thanks - Jim

next snippet is from a library of mine which works. I hope this works for you too:


<?php
function sendmail($mailto, $mailfrom, $mailsubject, $header, $footer, $body, $info)
{
 $emailtext='';
 $headertext='';
 $footertext='';
 
 $bodytext=$body;
 $mail_from=$mailfrom;
 $mail_to=$mailto;
	
 $check_sql = "SELECT tableid, keyid, value FROM pref where tableid='email'";
 sc_select(rs, $check_sql);	
 while (!$rs->EOF)
 {
   if (strcasecmp($rs->fields[1], 'smtpserver')==0) {
	   $mail_smtp_server=$rs->fields[2];
   }
   
   if (strcasecmp($rs->fields[1], 'userid')==0) {
	   $mail_smtp_user=$rs->fields[2];
   }
	
   if (strcasecmp($rs->fields[1], 'password')==0) {
       $mail_smtp_pass=$rs->fields[2];
   } 
					
   if ($mailfrom=='') {	 
     if (strcasecmp($rs->fields[1], 'from')==0) {
	     $mail_from=$rs->fields[2];
     }
   }	   
etc.

Albert,

Thanks your reply was helpful. It looks like sc_select and sc_lookup both work in libraries. Once the functions are placed inside of classes, the macros stop working.

If anyone can prove me wrong, I’d much rather code with classes :slight_smile:

  • Jim