So I have a function that handles queries:
function cfquery($query){
// Connection's Parameters
$db_host="localhost";
$db_name="d";
$username="u";
$password="p";
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
// Connection
mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
// Query
$sql = $query;
$results = mysql_query($sql);
return $results;
}
And I'm trying to write a function that will take the results and put them into an array, but this function is generating a 'resource', and everything I'm finding on the internet doesn't work for that data type, or isn't generated dynamically - like you have to know the column names in order to get to the data.
For instance:
while ($row = mysql_fetch_array($results)){
echo $row['name'] . ',' ;
echo $row['email'] . ',' ;
echo $row['city'] . ',' ;
}
I'm looking for something that will get the column names from the results. Like this:
$array = new array();
loop rows index x {
loop column_names index y {
$array[x][y] = $results[rows][column_names];
}
}
If you can't tell, I'm transitioning from ColdFusion, so I have only a vague idea of what a "resource" is (after reading some documentation), and no idea why I can't get an array out of it.