I use the following function to select data from a MYSQL database:
if (!function_exists('select_array_where')) {
function select_array_where($what, $from, $where){
$mysqli = new mysqli("host", "user", "password", "db");
if ($mysqli->connect_errno)
{
echo "<br>Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error . "<br>";
}
$result = $mysqli ->query("SELECT $what FROM $from WHERE $where");
$array = Array();
while ($row = mysqli_fetch_assoc($result)) {
$array[] = $row[$what];
}
print_r ($array);
return $array;
}
}
Which works perfectly well if $what has only one value:
$name_array = Array();
$name_array =& select_array_where("name", "inter_company", "transaction_type='interest'");
But it does not work in the following case:
$company_int_array = array();
$company_int_array =& select_array_where("amount, perc", "inter_company", "transaction_type='interest'");
I've a feeling it relates to punctuation and have tried movies comma's, " and ' around, in and out but nothing helps...
Anyone an idea what I'm doing wrong?
"amount, perc",these would need to be separated"amount", "perc",`around each word theamount, percwith your existing quotes, or wrapping the whole thing.