Dropdown Ajax onChange not filling in resultset

The following code always fills in 99999 in the client_id regardless of which client I select in the dropdown. Id is an interger. That suggests that there is nothing in the result set (which makes no sense)?

What am I missing?

/**
 * Selecting a field from another table
 */

// Check for record
$check_sql = "SELECT client_id"
   . " FROM bill_clients"
   . " WHERE client = '" . {Client} . "'";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]}))     // Row found
{
    {client_id} = {rs[0][0]};
}
        else     // No row found
{
            {client_id} = '99999';

}

what daa type is {client}?

Client is varchar.

And in SC it is a “Select” dropdown field.

If it matters I’m on the current build: V8.1.056

You need know if varieble {Client} has the value selected. Use modo debug.

Thank you Alvagar

How do I turn on debugging?

Application / Settings / Debug Mode

That’s great, Alvagar. Got it working. Apparently it has to do with the way SC works. My dropdown select statement was:


SELECT client _id, client 
FROM bill_clients 
ORDER BY client

Once I changed it to:


SELECT client 
FROM bill_clients 
ORDER BY client

Then it worked.

Glad to know how the debugger works. Very helpful.

I’m using this code in a 2nd dropdown and it works:


SELECT fee_id, fee_name
FROM bill_fees 
ORDER BY fee_name

However, if I add a where clause it fails.


SELECT fee_id, fee_name
FROM bill_fees 
ORDER BY fee_name
WHERE Active = 1

“Active” is tinyint.

Where am I going wrong?

Sorry, I’m blind…
it works:


SELECT fee_id, fee_name
FROM bill_fees
WHERE Active = 1
ORDER BY fee_name

:wink: OK. …