dolythgoe
asked on
php in_array efficiency
Hello,
I'm a little concerned over computing cost of a feature that I hope some people can give me reassurance :)
I have a sphinx search on documents with some features to both 'favorite' and 'mark as read' on each result returned.
These features which are available require a store of all items marked as either favorited or mark as read.
Favorited max cap is 2000 and mark as read can go 2000+
My theory is to store all the doc_ids in 2 arrays upon login. So my first thought is, is that dangerous to store so many values in a $_SESSION?
Next thought is when the results are returned, I need to run something like the below:
Just need some expert opinion really on the best way of achieving this - trying to avoid db queries where I can
$doc_id's are INTs
Cheers
I'm a little concerned over computing cost of a feature that I hope some people can give me reassurance :)
I have a sphinx search on documents with some features to both 'favorite' and 'mark as read' on each result returned.
These features which are available require a store of all items marked as either favorited or mark as read.
Favorited max cap is 2000 and mark as read can go 2000+
My theory is to store all the doc_ids in 2 arrays upon login. So my first thought is, is that dangerous to store so many values in a $_SESSION?
Next thought is when the results are returned, I need to run something like the below:
if(in_array($doc_id, $_SESSION['favorites_array']))
{
$favorite_link = 'Favorited';
}
else
{
$favorite_link = '<a href="addtofavorites.php">Add to Favorites</a>';
}
if(in_array($doc_id, $_SESSION['read_array']))
{
$read_link = 'Marked as Read';
}
else
{
$read_link = '<a href="addtofavorites.php">Mark as Read</a>';
}
Just need some expert opinion really on the best way of achieving this - trying to avoid db queries where I can
$doc_id's are INTs
Cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome, gotta love php's ability to have a function for everything!
Cheers guys
Cheers guys
ASKER
There's 24 results per page so php has to either lookup per result or there might be a way of getting the 24 id's and compare array against array to produce an array of matches if you see what I mean. Then compare the much smaller array of matches with each listing...does that make sense?