note 60924 deleted from function.mysql-fetch-assoc by tularis
| From: | tularis@php.net | Date: | Fri, 20 Jan 2006 10:24:35 +0000 |
| Subject: | note 60924 deleted from function.mysql-fetch-assoc by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-102153@lists.php.net to get a copy of this message | ||
Note Submitter: zach at zachtv dot com
Reason: bad code
----
I'm just getting back to php/sql and I was finding I writing too many if elses when i decided
to make a function that returned an array of values i needed so i could just loop through it or peck
and hunt if i wanted.
#################################################
# function returns an array of associative values
function doSQL ($q)
{
// query the database
$result = mysql_query($q);
if(!$result)
{
sqlError();
}
else
{
// take the table info and return it as an array
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$sql_array = array_map(null, $row);
return $sql_array;
}
}
}
$myArray = doSQL('SELECT * FROM some_table WHERE some_value = some_number);
print_r($myArray);