Empty Array Being Returned

I’m trying to create a new array from a single line of data from each row returned in the query array.

The data is being returned from the query but the array is not being built.

Please advise?

function psl_getRegions($agency, $user){
		$sql="SELECT * FROM `users` WHERE `user_relationshipAgency`='{$agency}' AND user_id != '{$user}'";
		$results = $db->query($sql);
		$rows = mysql_fetch_array($results,MYSQL_ASSOC);
		
		$output = array();
		
		foreach ($rows[15] as $row) {
			$output[] = $row;
		}
		
		//return $output;


	}
	

Try this:


function psl_getRegions($agency, $user) {
        
        $sql=sprintf(
           "SELECT * FROM `users` WHERE `user_relationshipAgency`='%s' AND user_id != '%s'",
           mysql_real_escape_string($agency),
           mysql_real_escape_string($user)
        );
        $results = $db->query($sql);

        $output = array();
        while ($row=mysql_fetch_array($results,MYSQL_ASSOC)) {
            $output[] = $row;
        }
        return $output;
} 

I guess you’re interested in getting the value of column 15 for all rows. If so, try this:

function psl_getRegions($agency, $user){
	$sql="SELECT * FROM `users` WHERE `user_relationshipAgency`='{$agency}' AND user_id != '{$user}'";
	$result = $db->query($sql);
	$output = array();
	while($row = mysql_fetch_array($result,MYSQL_BOTH)){ // the columns can be retrieved either by index number or name
		$output[] = $row[15]
	}
	var_dump($output);
}