SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2005
    0 Post(s)
    0 Thread(s)

    Array help please

    Hi ALL

    Some help with arrays please.

    I have a list of products in a database,I want them to be classified as
    major product and minor products, but what can be minor for one can he major for another,so in the actual database we make no distinction between the products, just in the customers selection.

    So when I read information from the products table, the first form lists all the products like.

    Tiolet paper

    A visitor then checks what he identifies as major products, when he hits the
    next button another form shows information from the same product table
    under the heading minor products, but if for example he selected icecream as a major product I donot want it to be listed on the minor products section.
    So we will have for example

    Tiolet paper

    I am sorry if I am vague here, but I am trying my best to explain

    Please help

  2. #2
    SitePoint Enthusiast shineability's Avatar
    Join Date
    May 2005
    Mechelen [Belgium]
    0 Post(s)
    0 Thread(s)
    If you would use checkboxes to let the user choose whether a product in the list is a major product you could output the following HTML:

    HTML Code:
    <form action="list_page.php" method="post" name="listform" id="listform">
        <li><input type="checkbox" name="productID[]" value="1" />Icecream</li>
        <li><input type="checkbox" name="productID[]" value="2" />Jelly</li>
        <li><input type="checkbox" name="productID[]" value="3" />Toilet paper</li>
        <!-- etc ... -->
      <input type="submit" name="showMinorProducts" value="Show minor products" />
    In your list_page.php document you could do the following:

    PHP Code:

    if (isset($_POST['showMinorProducts'])) {
    // Assign selected productID's to array majorID
    $majorID $_POST['productID'];

    // Do a query on the products excluding the products that 
      // have been selected as major products. 
      // E.g. (i don't know your table definition)
    $minorResult $db->query("
          productID not in (" 
    array_implode(", "$majorID) . ")

    // Display the minor products

    A bit rough, i know, but i'm not 100% sure what you mean.
    Did this help at all?


  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2005
    0 Post(s)
    0 Thread(s)
    Hi Thanks for replying.

    I am going to test your code to see if it will help me.

    I am going to try and explain what I want again, I hope I do better this time.

    What we have is a list of products in a mysql database.Examples of products are.

    Tiolet roll
    Hair Cream
    Juice ............and so on. up to 100 products

    We want to ascertain from people, what they consider a major product and what is a minor product in there household.So a product like perfume might be major for one person and might me minor for another.

    So I read from the databse and siplay all the products as checkboxes, all 100 products.Now the first screen will say something like:-

    Please select all major products from the list below:-

    all 100 products will be listed as checkboxes.The visitor then checks what he considers major

    When the visitor hits the next button as weill have something like

    Please select all minor products from the list below:-

    However at all times we are reading form the same products tables the products in the major and minor section is the same.

    My challenge is that if a person selects 3 items in the major section, that
    3 must be excluded in the list that we display in the minor section.

    So tiolet roll which was listed initially as a product in the major section is selected then the list of products in the minor section must exclude tiolet roll.

    Sorry guys I have the design in my head, I just donot know how to code it.

    The closest I can get to explain is if I have an array of products :-

    $product_list1=array("Tiolet roll","sweet","choclate","paper","perfume")
    $product_list2=array("Tiolet roll","paper","perfume")

    Then $product_list3 is actually the difference between $product_list1 and $product_list2.

    Hence $product_list3=array("sweet","choclate","paper")

    Please help


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts