Eek!! Never understand that code in a million years (Join that to never understand women at all)
It's interesting but not outputting the contacts for each person after each person's details from db_addresses.
Thanks for the help Spikey, when the weather warms I can actually think a little when the neurons start to flow.
This is what I will do below as I understand it. Just going to flesh the statements out a bit with some conditionals that come from text boxes: (Obviously lots of custom stuff in there but this has worked befored. Not elegant but works)
Code: Select all
Procedure ShowCategoryAddresses()
;
GetCurrentCategory()
;
; Debug "The current line is::: " + Str(CurrentCategoryLine.i)
; Debug "The current category name is::: " + CurrentCategory.s
; Debug "The current table name is::: " + TableName.s
; Debug "The current procedure is::: " + #PB_Compiler_Procedure
; Debug "-----------------------------------------------------------------------------------------"
; Remove the columns for this database
RemoveGadgetColumn(#Gadget_MyInfo_Titles, #PB_All)
; Set the columns for this database
AddGadgetColumn(#Gadget_MyInfo_Titles, 1, "Item title", 440)
AddGadgetColumn(#Gadget_MyInfo_Titles, 2, "Home phone", 100)
AddGadgetColumn(#Gadget_MyInfo_Titles, 3, "Work phone", 100)
AddGadgetColumn(#Gadget_MyInfo_Titles, 4, "Mobile", 100)
AddGadgetColumn(#Gadget_MyInfo_Titles, 5, "Fax number", 100)
AddGadgetColumn(#Gadget_MyInfo_Titles, 6, "Email address", 160)
AddGadgetColumn(#Gadget_MyInfo_Titles, 7, "Callsign", 80)
AddGadgetColumn(#Gadget_MyInfo_Titles, 8, "Archived", 0)
AddGadgetColumn(#Gadget_MyInfo_Titles, 9, "Favourite", 0)
AddGadgetColumn(#Gadget_MyInfo_Titles, 10, "Locked", 0)
AddGadgetColumn(#Gadget_MyInfo_Titles, 11, "Deleted", 0)
AddGadgetColumn(#Gadget_MyInfo_Titles, 12, "Updated", 0)
AddGadgetColumn(#Gadget_MyInfo_Titles, 13, "Recordid", 0)
;
Queue\CurrentCategory.s = Category\Category.s
Queue\CategoryItems.s = Category\Hasitems.s
;
Program\LastCategory.s = Queue\CurrentCategory.s
;
;Debug "We got a current category selection::: " + Queue\CurrentCategory.s
; Keep track of the current line to feed to the string display routine
CurrentLine.i = #False
; Create a new list of record numbers we will use to fetch data with for linked tables
NewList RecordNumbers.s()
; Fetch all recordid numbers from the selected table
If DatabaseQuery(Program\DatabaseHandle, "SELECT recordid FROM db_addresses ORDER BY recordid") <> #DatabaseQueryFail
While NextDatabaseRow(Program\DatabaseHandle) <> #NoDatabaseRows
CurrentRecordid.s = GetDatabaseString(Program\DatabaseHandle, 0)
If CurrentRecordid.s <> #Empty$
AddElement(RecordNumbers.s())
RecordNumbers.s() = CurrentRecordid.s
Else
; There was no current record id. Should never happen
EndIf
CurrentRecordid.s = #Empty$
Wend
FinishDatabaseQuery(Program\DatabaseHandle)
Else
SetInfoBarArea("Headings", "Error", "The database query has failed or was empty: " + DatabaseError(), #PB_Compiler_Procedure)
EndIf
; Contact new list for temporary contact data to feed to display routine
NewList TempContacts.ContactData()
; Iterate through the linked list and fetch each record along with the associated contact data
ForEach RecordNumbers.s()
; Fetch all address data from the db_addresses table for each recordid in the list
SetDatabaseString(Program\DatabaseHandle, 0, RecordNumbers.s())
If DatabaseQuery(Program\DatabaseHandle, "SELECT * FROM db_addresses WHERE recordid = ?") <> #DatabaseQueryFail
While NextDatabaseRow(Program\DatabaseHandle) <> #NoDatabaseRows
CurrentRecordid.s = GetDatabaseString(Program\DatabaseHandle, 0)
CurrentRecordid.s = #Empty$
Wend
FinishDatabaseQuery(Program\DatabaseHandle)
Else
SetInfoBarArea("Headings", "Error", "The database query has failed or was empty: " + DatabaseError(), #PB_Compiler_Procedure)
EndIf
; Fetch all contact data for each recordid in the list that has linked contact data
SetDatabaseString(Program\DatabaseHandle, 0, RecordNumbers.s())
QueryString.s = "SELECT contacttype, contactdata FROM db_addressescontacts WHERE recordid = ?"
If DatabaseQuery(Program\DatabaseHandle, QueryString.s) <> #DatabaseQueryFail
While NextDatabaseRow(Program\DatabaseHandle) <> #NoDatabaseRows
CurrentContactType.s = GetDatabaseString(Program\DatabaseHandle, 0)
CurrentContactData.s = GetDatabaseString(Program\DatabaseHandle, 1)
If CurrentContactData.s <> #Empty$
AddElement(TempContacts.s())
TempContacts.s()\contacttype.s = CurrentContactType.s
TempContacts.s()\contactdata.s = CurrentContactData.s
Else
; There was no current record id. Should never happen
EndIf
CurrentRecordid.s = #Empty$
Wend
FinishDatabaseQuery(Program\DatabaseHandle)
Else
SetInfoBarArea("Headings", "Error", "The database query has failed or was empty: " + DatabaseError(), #PB_Compiler_Procedure)
EndIf
; Display the new string of address data, parse the list for each line
DisplayAddressTitleString(CurrentLine.i, List ShowContacts.TempContactsData())
;
CurrentLine.i + 1
;
Next
EndProcedure