Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:19:50+00:00 2026-05-28T13:19:50+00:00

I have set the PHP variable $accountnumber to be that of the user who

  • 0

I have set the PHP variable $accountnumber to be that of the user who is viewing their profile page. On the page, I have a block with the user’s information populated from the database, and I have a list of all products that we have, and I want to put a check mark next to each one that the customer has by assigning a class to it.

Here are my tables:

products
id | name | url    | weight
100  p1     p1.html  1
101  p2     p2.html  2
102  p3     p3.html  3
103  p4     p4.html  4
104  p5     p5.html  5
105  p6     p6.html  6

products_accounts
account_number | product_id
0000001           100
0000001           104
0000001           105
0000002           101
0000002           103
0000002           104
0000002           105
0000003           100
0000003           102

I tried a LEFT OUTER JOIN, but was not able to determine if the $accountnumber matched an account_number in the products_accounts table for a specific product_id. The only way that I was able to accomplish this was to add a WHERE statement like this:

WHERE products_acccounts.account_number = '$accountnumber'

It gave the proper class to the product, but only showed the product that they had instead of all.

Here’s my code:

$sql ="
SELECT
    products.id,
    products.name,
    products.url,
    products_accounts.account_number
FROM
    products
LEFT OUTER JOIN
    products_accounts
ON
    products.id = products_accounts.product_id

";

$sql .="
GROUP BY
    products.id
ORDER BY
    products.weight
";

$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
    echo '<span class="'; if($row['account_number'] == '$accountnumber')
    { echo'product_yes">'; } else { echo 'product_no">'; }
    echo '<a href="' . $row['url'] . '">' . $row['name'] . '</a><br /></span>';
}

If a customer has all product except P2 and P5, it SHOULD display like this:

✓P1

P2

✓P3

✓P4

P5

✓P6
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:19:51+00:00Added an answer on May 28, 2026 at 1:19 pm
    $getproducts = mysql_query("
    SELECT id, name, url
    FROM products
    ORDER BY weight ASC");
    
    while ($rowproducts = mysql_fetch_assoc($getproducts)) {
    
    $product_id = $rowproduct['id'];
    $product_name = $rowproduct['name'];
    $product_url = $rowproduct['url'];
    
    $getuserhasproduct = mysql_query("
    SELECT DISTINCT product_id
    FROM products_accounts
    WHERE account_number = $accountnumber
    AND product_id = $product_id");
    $user_has_product = mysql_num_rows($getuserhasproduct);
    
    if($user_has_product){
    $class = "checked";
    }
    
    echo "<span class='$class'><a href='$product_url'>$product_name</a></span>";
    unset($class);
    } // end loop 
    

    This might help with performance

    $getproducts = mysql_query("SELECT id, name, url,
    (SELECT DISTINCT product_id
    FROM products_accounts
    WHERE account_number = '$accountnumber'
    AND product_id = products.id) AS product_count
    FROM products
    ORDER BY weight ASC");
    
    while ($rowproducts = mysql_fetch_assoc($getproducts)) {
    
    $product_id = $rowproduct['id'];
    $product_name = $rowproduct['name'];
    $product_url = $rowproduct['url'];
    $product_count = $rowproduct['product_count'];
    
    if($product_count > 0){
    $class = "checked";
    }
    
    echo "<span class='$class'><a href='$product_url'>$product_name</a></span>";
    unset($class);
    } // end loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have a set of words that's retrieved by php and displayed on
I have some values in a PHP variable that is the address of customer.
I have code which passes php variable to another page on my site: echo'<a
I have a sendemail.php set up for sending me information from a form. The
I need to set a PHP $_SESSION variable using the jQuery. IF the user
I have set values in app_controller.php and i can use those variable in 'default.ctp'.
I am trying to set cookies to a php session variable so that a
we have set session_gcmaxlife=5 in php.ini but session variable on server are not destroyed
I am developing w php web site. Here I have set a php cookie
I have set up a php script to receive url data like this: http://giffgaff.liamwli.co.uk/?name=liamwli

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.