Working with PHP Arrays from sc_lookup()

Im looking for advice on working with Arrays built from the sc_lookup() macro.

It returns the database query as a multidimensional array WITHOUT column names. Is there any way to get the column names from this query?

Example:

sc_lookup(MyArray,‘select columnA,columnB from MyTable’);

would return MyArray[0][0] as the data in columnA and MyArray[0][1] as the data in columnB first row.
MyArray[1][0] for data in columnA 2nd row and MyArray[1][1] as data in columnB 2nd row.

and so on.

What’s the best way to get this indexed array to an associate array where I have the column names?
Is there a way to get the column names with built in Scriptcase macros?

Thanks for any pointers!

Hi yourguide,
here is a solution using sc_select, which I’m using to retrieve data:

sc_select(my_data, "select * from customers");
if ({my_data} === false)
	{
	   echo "Access error. Message =". {my_data_erro};
	}
else
	{
		if (!{my_data}->EOF)
			{
				foreach({my_data}->fields AS $field_name=>$field_content)
					{
						if (!is_numeric($field_name))
							{
								echo "<br>fieldname: " . $field_name . " - content: " . $field_content;
							}
					}
			}
	{my_data}->Close();
	}

This will give you an output similar to:

fieldname:customerid - content: ALFKI
fieldname:companyname - content: Alfreds Futterkiste
fieldname:contactname - content: Maria Anders s
fieldname:contacttitle - content: Sales Representative
fieldname:birthdate - content: 1974-07-27
fieldname:country - content: DE
fieldname:regionid - content: 6
fieldname:stateid - content: SA
fieldname:city - content: Berlin
fieldname:address - content: Obere Str. 57
fieldname:postalcode - content: 12209
fieldname:phone - content: 30074321
fieldname:fax - content: 030-0076545
fieldname:cityid - content: 72058
fieldname:creditlimit - content: 3367.41
fieldname:cardtype - content:
fieldname:cardnumber - content:
fieldname:notes - content:

I hope, this will help you.

Sincerely

Gunter Eibl

1 Like

Thank you Gunter, I’ll put this to use immediately!