Jump to content

Logic to remove array items as a recommendation engine to show best solution


brentman

Recommended Posts

I have users in my database with many stored points ie age, gender, interests etc. about 20 points in all.

 

I have a table of products that I want to recommend only applicable products. They each have saved like minage, maxage, gender, interest etc for the ideal consumer. ie dress gender=f

 

This is the bare bones of what I have so far:

$result = mysql_query("SELECT * FROM user_table WHERE hash='$session_id'");
$rowuser = mysql_fetch_array($result);

$result = mysql_query("SELECT * FROM products");
$rowproducts = mysql_fetch_array($result);

So now I have $rowuser['gender'] = m , how do I remove all from $rowproducts where gender = f?

 

Is there a best way to do this knowing I have about 20 points to go through before I am left with an array with just the best selection of products for this user in it?

Hi,

 

and what exactly prevents you from using the WHERE clause or doing a join? Unless your rules are so complex that they exceed the capabilities of MySQL, this is simply a matter of writing one query:

SELECT
    -- something useful, not just "*"
FROM
    products
    JOIN users
    ON
        products.gender = users.gender
        AND ...
WHERE
    users.id = 1
;

I have a person who is male, aged 30 and has kids.

 

I have a list of products with information like (product should only be shown to people with kids or product should only be shown to men aged 30 or older)

 

I have an array of the persons details and an array of all products with their details.

 

How do I remove the products from the array that do not match the users details. ie remove dresses when the user is a male.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.