Button code --> Exist records on a table ? How make it working ?

Hi all,

I’m trying to make a test to check if there are or not records in a table within the code of a button (Create Order) .
If not I want to send a message otherwise do other things and create Order and Rows.

Here down the code that do not work properly.
Running the SELECT EXISTS on mysql the response is 0 but I read somewhere that means false… ;-(

$sql_check_div_0 = “SELECT EXISTS (SELECT * FROM products_selected)”;

sc_lookup(check_div_0,$sql_check_div_0);
$check = {check_div_0[0][0]};

if ($check == false)
{sc_confirm(“No records available”);
sc_redir(grid_products_for_order, “_parent”);}

else
something else…

Try select count(*) as cnt from products_selected to find out if the count is > 0. Then you can simply test the value.

Hi Albert,

Thanks
I did the code below withing the button code.
Select works in mysql and give 0 as reply.
I’m really astonished becouse this part of code is not taken in consideration at all.
Why I don’t see the echo message for istance ???
Code run starts always after else …
Is there a reason ?? What I’m wronging ?

First time I found the table empty I would like to send a warning message to user.

$sql_check_div_0 = “SELECT COUNT(*) FROM products_selected”;

sc_lookup(my_data, $sql_check_div_0);
echo “AAAAAAAAA” .{my_data[0][0]};
if ({my_data[0][0]} == 0)
{
echo “Access error. Message=”. {my_data_erro} ;
}
else
{
create…
}

Now I’ve tried just now using select and changing the test to < 1 and it seems better

$sql_check_div = “SELECT COUNT(*) FROM products_selected”;
sc_lookup(my_data, $sql_check_div);
if ({my_data[0][0]} < 1 )
{ echo “NO ROWS”; }

else
{
sc_confirm(“ORDER CREATION”);

}

The problem was connected to sc_confirm .
Once I transformed it into ‘echo’ it started to work .

What mess sc_confirm makes into the code ??? Is there a reason ??

else
{
echo "ORDER CREATION ";

}