SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    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.


    Icecream
    Jelly
    Tiolet paper
    etc
    etc

    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

    Jelly
    Tiolet paper
    etc
    etc

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

    Please help
    Niva

  2. #2
    SitePoint Enthusiast shineability's Avatar
    Join Date
    May 2005
    Location
    Mechelen [Belgium]
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    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">
      <ul>
        <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 ... -->
      </ul>
      <input type="submit" name="showMinorProducts" value="Show minor products" />
    </form>
    In your list_page.php document you could do the following:

    PHP Code:
    <?php

    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("
        select 
          * 
        from 
          product 
        where 
          productID not in (" 
    array_implode(", "$majorID) . ")
      "
    );

      
    // Display the minor products
      
    print_r($minorResult);
    }

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

    M.

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    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
    Perfume
    Hair Cream
    Sweets
    Choclate
    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
    Niva


Bookmarks

Posting Permissions

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