rony2006 Posted April 1, 2016 Share Posted April 1, 2016 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? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 1, 2016 Moderators Share Posted April 1, 2016 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: expandcollapse popupHotKeySet("{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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rony2006 Posted April 1, 2016 Author Share Posted April 1, 2016 Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now