No announcement yet.

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

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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)";

    $check = {check_div_0[0][0]};

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

    something else......

  • #2
    Try select count(*) as cnt from products_selected to find out if the count is > 0. Then you can simply test the value.
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development /


    • #3
      Hi Albert,

      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} ;

      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"; }

      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 ??

      echo "ORDER CREATION ";
      Last edited by giovannino; 10-16-2014, 06:36 AM.