hello i would like to shorten my code and would like to combine two functions that exactly do the same.
so i got this:
function a($a){
global $db;
$query = $db->query("SELECT col_a FROM table WHERE Field= '$a' ");
$check = $query->fetch_assoc();
$return_a = $check['col_a'];
return ($return_a);
}
function b($a){
global $db;
$query = $db->query("SELECT col_b FROM table WHERE Field= '$a' ");
$check = $query->fetch_assoc();
$return_b = $check['col_b'];
return ($return_b);
}
so i thought i could combine both into one:
function ab($a){
global $db;
$query = $db->query("SELECT col_a, col_b FROM table WHERE Field= '$a' ");
$check = $query->fetch_assoc();
$return_array = array( $check['col_a'], $check['col_b'] );
return ($return_array);
}
this does not seems to work. i tried reading out the array by using:
$db_data = ab($a);
echo $db_data['col_a'];
echo $db_data['col_b'];
so if there is someone who could tell what am i doing wrong i really would appreciate.
thanks alot.