Page 1 of 1

How to get columns and values from database in one array

Posted: Tue Apr 27, 2021 4:58 pm
by oli
Hi,
I'm searching a way how to get all column names and values from a sql SELECT statement into one array.
Usually I'd use mysqli_fetch_assoc or fetch(PDO::FETCH_ASSOC) but both options doesn't work.

Is there any other possibility?

BR,
Oliver

Re: How to get columns and values from database in one array

Posted: Tue Apr 27, 2021 5:03 pm
by kev1n
Hi,

Something like this?

Code: Select all

function getColumnsArray($table){

	$a  = array();
	$s =  "SHOW COLUMNS FROM `$table`";
	$t = nuRunQuery($s);

	while($r = db_fetch_row($t)){
		$a[] = $r[1];
	}

	return $a;

}

$arr = getColumnsArray('your_table_name_here');

Re: How to get columns and values from database in one array

Posted: Tue Apr 27, 2021 10:25 pm
by oli
Thank you. That is was I'm looking for!

Re: How to get columns and values from database in one array

Posted: Mon May 03, 2021 6:10 pm
by apmuthu
Should this get into the core?