rony2006

Listview data update - if array is changed

3 posts in this topic

Hello,

I have a script were I have a GUI with a listview. The data from listview is from an 2D array (a table from mysql query).

When I start the script, I want to have the listview with the 2D array and then to check each 2 sec if the table if change then to also change the data from listview. If the data from table is the same with the data from listview, then do nothing.

I tried all sort of things but I cannot get the script working as I want.

 

This is the part of the script that add array to listview:

$linterogare = "SELECT * FROM `tichete` WHERE control_id<3 ORDER BY `prioritate` ASC" 
        
    

        $laOk = _EzMySql_GetTable2d($linterogare)
        $error = @error
        If Not IsArray($laOk) Then MsgBox(0, $stMySqlStatement & " error", $error)
            
        Global $date = $laOk

        _GUICtrlListView_SetItemCount($lista, 5000)
        _GUICtrlListView_AddArray($listatickete, $date)
        
        Sleep (1500)
        ;_GUICtrlListView_DeleteItem($listatickete, 0) ; sterge primu element (colum header)
        
        
        $linterogare = "SELECT * FROM `tichete` WHERE control_id<3 ORDER BY `prioritate` ASC" 
        $laOk1 = _EzMySql_GetTable2d($linterogare)
        
        ;If not $laOk1 = $date Then 
        ;MsgBox (0, "NIMIC NOU", "fdfds")
        ;Else
        
        ;_GUICtrlListView_SetItemCount($lista, 5000)
        ;_GUICtrlListView_AddArray($listatickete, $laOk1)
        
        _GUICtrlListView_DeleteAllItems($listatickete) ;sterge toate itemele din lista
    
    
        ;MsgBox (0, "fdfsdfds", "fdfds")
    
_EzMySql_Close()
_EzMySql_ShutDown()
            
        ;EndIf

What you see with ; is what I tried to do. First I thought that is good to compare the data that was sent to listview with a new SQL query. If the value of array is the same, then do nothing, else send the new data to the listview.

 

With the script from above, the data from listview is deleted each 1,5 sec and new data is added. (no matter if is the same).

 

Any ideas how I can update the data from the listview ONLY if the data from mysql is changed?

Share this post


Link to post
Share on other sites



rony2006,

Please do not send PMs asking for help as the Forum rules specifically prohibit this for 2 reasons:

  • The forum is here to help everyone - if you get private help then no-one else can benefit.
  • Do you have any idea how many PMs asking for help people like me get despite that rule?  Answer: a great deal!

So please do not do it again.

Here is an example of how I would go about checking whether the data had changed:

HotKeySet("{ESC}", "_Exit")

Local $aLastQuery[1][1]

$nBegin = TimerInit()

While 1

    ; Every 2 secs
    If TimerDiff($nBegin) > 2000 Then
        
        ; Get the latest data in array form
        $linterogare = "SELECT * FROM `tichete` WHERE control_id<3 ORDER BY `prioritate` ASC" 
        $laOk = _EzMySql_GetTable2d($linterogare)
        $error = @error
        If Not IsArray($laOk) Then MsgBox(0, $stMySqlStatement & " error", $error)
        
        ; Clear flag
        $fArrayChanged = False
        
        ; Check if arrays sizes are identical
        If UBound($laOk) <> UBound($aLastQuery) Or If UBound($laOk, 2) <> UBound($aLastQuery, 2) Then
            ; There is a change in size
            $fArrayChanged = True
        Else
            ; Same size so look at each individual element
            For $i = 0 To UBound($laOk) - 1
                For $j = 0 To UBound($laOk, 2) - 1
                    If $laOk[$i][$j] <> $aLastQuery[$i][$j] Then
                        ; Element has changed
                        $fArrayChanged = True
                        ; No point in looking further
                        ExitLoop 2
                    EndIf
                Next
            Next
        EndIf
        
        ; Has array changed?
        If $fArrayChanged Then
            ; Here you clear the existing ListView and load the new data from $laOK
            
            
            ; Now save the new array for the next comparison
            $aLastQuery = $laOk
        EndIf
        
        ; Reset the timestamp to wait another 2 secs
        $nBegin = TimerInit()
    
    EndIf   
    
WEnd

Func _Exit()
    Exit
EndFunc

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now