Hi Everyone,
Pretty much, I am trying to store an array in my Session class to hold a users saved items, that are stored in their MySQL Database, but it seems to only be storing the first item...
Basic Code (very slimmed down):
Session.php
class Session
{
var $userItems = array(); //The array holding all users saved items
function checkLogin() {
//code that checks if user is logged in goes here...
//confirms and set username SESSION variable
$this->userItems = $database->getUserSavedItems($_SESSION['username']);
}
Database.php
function getUserSavedItems($username){
$q = "SELECT ItemID FROM ".TBL_SAVED_ITEMS." WHERE username = '$username'";
$result = mysql_query($q, $this->connection);
/* Error occurred, return given name by default */
if(!$result || (mysql_numrows($result) < 1)){
return NULL;
}
/* Return result array */
$dbarray = mysql_fetch_array($result);
return $dbarray;
}
When I try to print out the contents of the Array, I get something like the line below (which spits out two of the same ItemID's...aka 1 DB row):
Array ( [0] => 11566001 [ItemID] => 11566001 )
How would I be able to store every ItemID that the user has under his/her username?
I am trying to store it like this because I would like to use this information to make the user know which items are already saved. For example, when searching the site, they would see something like "Remove this Item", if it's in their DB and "Save this Item", if it is not.
Thank you for your time,
Tec