Set field value based on sql statement

I have this sql statement which produces the desired results,

SELECT COUNT(DISTINCT OEMCode) FROM master_data
WHERE repDate = '2013-04-01'

I wish to popular a checkbox field based on the results using an if statement at the “on Load” stage I think, so what Im trying to achieve is something like:

if ($sql>>=1)
     {
    {newcheckboxfield} = 1;	
    } 
else
	{
	{newcheckboxfield} = 0;
	}

I cant seem to put the 2 together or find a similar example? any help appreciated.
Thanks

In the right section of your event php edit code there’s a code snippet to select data from a sql statement. It will give you the result in an array like $rv[0][0]. You change the sql statement to your need and apply your code.

So you will get something like:


.. your code snippet for selecting data
if (isset($rv[0][0])) {
  if ($rv[0][0]>1) 
  {
   {newcheckboxfield} = 1;     
  }
  else
  {
    {newcheckboxfield} = 0;     
  }
}


That should do it, provided that you have configured your checkbox to respond to 1 and 0 (not Y and N)

Hello,

Please take a look at our sc_lookup macro: downloads.scriptcase.com.br/downloads/v7/manual/en_us/webhelp/manual_mp/28-Macros/00-macros_sc.htm#sc_lookup

regards,
Bernhard Bernsmann

Thank you aducom & bartho for your replies, I will be back on this later. However your time is appreciated. I need to check my approach as I may be going about this in the wrong way. See here