Jump to content

Array and SQL


Go to solution Solved by skybax,

Recommended Posts

Hello everyone, i have a problem, im using an array to read some data from mysql and i want to check if that array is not null 

$SQLCode_raport_tip2 =  "SELECT `Sala` , SUM(cantitate) FROM `raspandire` WHERE `data` BETWEEN '"&GUICtrlRead($data_de_la)&"' AND '"&GUICtrlRead($data_pana_la)&"'AND `Tip`=2 GROUP BY  `Sala`"
                $TableContents_tip2 = _Query($SQLInstance,$SQLCode_raport_tip2)
                    Global $bResult[10001][4] = [[10000, 4]]
                    Global $iIndex2
                            With $TableContents_tip2
                                    While Not .EOF
                                        $bResult[$iIndex2][0] = "Selector"
                                        $bResult[$iIndex2][1] = .Fields("Sala").value
                                        $bResult[$iIndex2][2] = .Fields("SUM(cantitate)").value
                                        $bResult[$iIndex2][3] = GUICtrlRead($curs_valutar)*251
                                        $iIndex2 = $iIndex2 + 1
                                        .MoveNext
                                    WEnd
                                EndWith

                    ReDim $bResult[$iIndex2][4]

If i run this code and it finds some inputs in mysql everything is ok, but if MySQL returned an empty result it crashes my program 

SELECT  `Sala` , SUM( cantitate ) 
FROM  `raspandire` 
WHERE  `data` 
BETWEEN  '2013-07-29'
AND  '2013-07-29'
AND  `Tip` =2
GROUP BY  `Sala`
Array variable subscript badly formatted.:
ReDim $bResult[$iIndex2][4]
ReDim $bResult[^ ERROR

What can i do to make it skip ReDim $bResult[$iIndex2][4] if the result is null? i have tried something like this but with no succes it crashes or it enters a loop and freezes the program

If $bResult <> "" Then
        MsgBox(-1,"TEST"," EMPTY")
    Else
        ReDim $bResult[$iIndex2][4]
EndIf
Link to comment
Share on other sites

  • Solution

Hi,

You may want to take a time to see this function: IsArray()

 

I have tried IsArray but with n success.

If IsArray($bResult) Then
    ReDim $bResult[$iIndex2][4]
EndIf

I still get this when i get a null result from mysql

ReDim $aResult[$iIndex][4]
ReDim $aResult[^ ERROR

LE: I managed to solve this by adding the condition to the $iIndex

 

If $iIndex2 > 0 then
ReDim $bResult[$iIndex2][4]
                        EndIf
Edited by skybax
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...