MySQL - Datagrid
Posted: Mon Feb 04, 2013 7:10 pm
Hi
I am calling data from my mySQL database and putting the data into my datagrid. Quite straight forward, but I hit a few issues when I call data from 2 separate tables in my database. I have the following code:
Problem is, some of the data overwrites from my 2 queries and not quite sure why. Can anyone spot the error in my code?
Thanks
Daniel
I am calling data from my mySQL database and putting the data into my datagrid. Quite straight forward, but I hit a few issues when I call data from 2 separate tables in my database. I have the following code:
Code: Select all
on mouseUp
## Connect to the database
put "mysql" into theDBType
put "www.xxxx.co.uk" into theDBHost
put "xxxx" into theDBName
put "xxx" into theDBUser
put "xxx" into theDBPassword
put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
if theConnectionID is an integer then
## Query the database for data
put revQueryDatabase( theConnectionID, "select * from QG where Dealer LIKE '" & (fld "Dealer") & "%'") into theCursor
put revQueryDatabase( theConnectionID, "select * from QGNew where DealerID LIKE '" & (fld "Dealer") & "%'") into theCursor2
//answer the result
if theCursor is an integer then
ConvertSQLCursorToArray theCursor, theDataGridArray
ConvertSQLCursorToArray theCursor2, theDataGridArray2
put the result into theError
if theError is empty then
## The cursor was successfully converted to an array.
## Assign it to the data grid. The 'firstname' and 'lastname' columns
## from the database cursor will appear in the matching columns
## in the data grid.
set the dgData of group "Glance" to theDataGridArray
end if
## Close the database cursor
revCloseCursor theCursor
end if
## Close the database connection
revCloseDatabase theConnectionID
else
answer "Error connecting to the database:" && theConnectionID & "."
end if
end mouseUp
command ConvertSQLCursorToArray pCursor, @pOutArrayA
local i,j
local theFields
local theError
## Get the names of all the columns in the database cursor
put revDatabaseColumnNames(pCursor) into theFields
if theFields begins with "revdberr," then
put item 2 to -1 of theFields into theError
end if
if theError is empty then
put 0 into i
## Loop through all rows in cursor
repeat until revQueryIsAtEnd(pCursor)
add 1 to i
## Move all fields in row into next dimension of the array
repeat for each item theField in theFields
put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[i][ theField ]
end repeat
revMoveToNextRecord pCursor
end repeat
end if
return theError
end ConvertSQLCursorToArray
Thanks
Daniel