Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

How to get columns and values from database in one array

Questions related to using nuBuilder Forte.
Post Reply
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

How to get columns and values from database in one array

Unread post 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
kev1n
nuBuilder Team
Posts: 4304
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

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

Unread post 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');
oli
Posts: 118
Joined: Sat Mar 20, 2021 3:22 pm
Has thanked: 4 times

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

Unread post by oli »

Thank you. That is was I'm looking for!
apmuthu
Posts: 249
Joined: Sun Dec 06, 2020 6:50 am
Location: Chennai, India, Singapore

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

Unread post by apmuthu »

Should this get into the core?
Post Reply