Array only returning one result? (Should return 2)
Posted: Tue May 25, 2010 4:35 pm
Hello all,
This is my first time toying with functions returning arrays so I'm sure the answer is simple, but please help.
I have a function doing my query:
Then I have my code using the function:
It's returning:
However if you run the same query in MySQL you get:
Where am I going wrong?
This is my first time toying with functions returning arrays so I'm sure the answer is simple, but please help.
I have a function doing my query:
Code: Select all
function fetch_category_discounts($cat_ID) {
mysql_connect(SQL_HOST_NAME, SQL_USER_NAME, SQL_PASSWORD) or die(mysql_error());
mysql_select_db(SQL_DATABASE) or die(mysql_error());
$result = mysql_query("SELECT * FROM discounts, category_relations WHERE category_relations.member_of = '$cat_ID' AND category_relations.id = discounts.id")or die(mysql_error());
return mysql_fetch_assoc($result);
}Code: Select all
$discounts = fetch_category_discounts($cat_ID);
print_r($discounts);Code: Select all
Array ( [id] => 1 [short_discount] => 15% Off International Flights [long_discount] => 15% Off all International Flights. Coach seating only. Must wear cool sunglasses when in flight. [merchant] => Delta [expiration] => 1277494242 [member_of] => 1 )Code: Select all
id short_discount long_discount merchant expiration id member_of
1 15% Off International Flights 15% Off all International Flights. Coach seating o... Delta 1277494242 1 1
2 Testing Short Discount I am a longer discount because I am the long_disco... HIM 2 1