Page 1 of 1

Write TextGadget text from php

Posted: Mon Apr 15, 2019 6:39 pm
by Efo74
hello, is there an example on how write textgadget text from php code ? Thank you for the support. What I want is write mysql database with php INSERT, than get latest insert id, and write this id into a textgadget ... possible ?

Re: Write TextGadget text from php

Posted: Wed Apr 17, 2019 9:24 am
by JCV
Hi Efo,

I used JSON and HTTPRequest to do this combine php + sb.
BTW, I'm new in SB. i'll still on trial version and I started last week. :D

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
  Protected material_request_record.material_request_query_result
  Protected record_no.i, start_time.i, process_time.i
  
  If Success
        If ParseJSON(0, Result$)
          ExtractJSONStructure(JSONValue(0), @material_request_record,  material_request_query_result)
          FreeJSON(0)
        Else
          Debug JSONErrorMessage()
        EndIf
        
      ClearGadgetItems(lst_material_request_status)
      record_no = 0
      Protected days_left.s
      ForEach material_request_record\Result()
        AddGadgetItem(lst_material_request_status, record_no, material_request_record\Result()\mat_req_ID + Chr(10) + material_request_record\Result()\UserName + Chr(10) + material_request_record\Result()\installation_bldg)
        record_no + 1
    Else
      Debug "HTTPRequest(): Error"
    EndIf
EndProcedure
  
Procedure get_material_request_list()
  Protected request.s, request_result.s, Filter, HttpRequest
  Protected NewMap Header.s()
  
  If CreateJSON(0)
    Filter = SetJSONObject(JSONValue(0))
    SetJSONString(AddJSONMember(Filter, "UserName"), "ALL")
    SetJSONString(AddJSONMember(Filter, "AnelID"), "") 
    SetJSONString(AddJSONMember(Filter, "Approved"), "")
    SetJSONString(AddJSONMember(Filter, "StatusType"), "")
    request = ComposeJSON(0)
    Debug request
    FreeJSON(0)
  EndIf
  
  Header("Content-Type") = "application/json"
  HTTPRequest(#PB_HTTP_Post, "get_material_list.php", request, @HttpGetEvent(), 0, Header())
EndProcedure

Re: Write TextGadget text from php

Posted: Wed Apr 17, 2019 7:47 pm
by Efo74
Thanks for your help, now I have to study your code :shock:

Re: Write TextGadget text from php

Posted: Thu Apr 18, 2019 5:14 am
by JCV
Hi, heres my sample of screenshot to give you idea. I already reached 800lines of code so I'll be purchasing soon to explore sb.
It looks fun and easy but need some tweaking to accomplish some task.
Thanks to all who share their tips and code here in forum.


Image