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?

Link to comment
Share on other sites

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
;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.