how to display products

Discussion in 'Customization & add-ons' started by heckubiss, Mar 24, 2006.

  1. heckubiss

    heckubiss New Member

    Joined:
    Jun 6, 2004
    Messages:
    21
    Hi,

    what is the php code to display a particular product and its price
    for instance I would like to display products 1 to 10 (along with there prices and names) on one page and 10 to 20 on another page
  2. heckubiss

    heckubiss New Member

    Joined:
    Jun 6, 2004
    Messages:
    21
    I already tried this from another post but it says "access is not allowed. please go to membership information page"

    What I want to do is to be able to display any product with its price even if user is not logged in

  3. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Is not it better to use PriceGroups (have a look in product settings, there is also description).
  4. heckubiss

    heckubiss New Member

    Joined:
    Jun 6, 2004
    Messages:
    21
    yes but i dont want it on my signup page. I want my sign up page to be clean.

    I want to make my own products page where I put a picture of the product, and under it I have code that will get the name of the product and the price.
  5. ianh

    ianh New Member

    Joined:
    May 31, 2005
    Messages:
    23
    I guess in theory (as in this has not been tested), you could try including a couple of aMember files in an otherwise clean php page (probably config.inc.php and mysql.inc.php?) to create a database connection and then call the relevant functions ( get_products_list(), get_product($product_id) ) and display the arrays.

    I suspect you would need to have some PHP skills including a good understanding of error messages and some patience...

    Any help? ian
  6. heckubiss

    heckubiss New Member

    Joined:
    Jun 6, 2004
    Messages:
    21
    I tried this:
    <?php
    include "amember/config.inc.php";
    $products = $db->get_product(22);
    print $products.title;
    print $p.title;
    ?>

    but all it returned was

    Arraytitletitle
  7. ianh

    ianh New Member

    Joined:
    May 31, 2005
    Messages:
    23
    Ok, looks slightly promising, try this:

    PHP:
    <?php
    include "amember/config.inc.php";
    $products $db->get_product(22);
    print_r($products);
    ?>
    If the database bit is working ok then $products should be an array of all the properties of product id 22. print_r is a general PHP command that will spit out the contents of that array. Let us know what happens.

    Ian
  8. heckubiss

    heckubiss New Member

    Joined:
    Jun 6, 2004
    Messages:
    21
  9. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    PHP:
    <?php
    include "amember/config.inc.php";
    $p $db->get_product(22);
    print 
    'title='  $p['title']  . '<br>';
    print 
    'price=' $p['price'] . '<br>';
    ?>
  10. ianh

    ianh New Member

    Joined:
    May 31, 2005
    Messages:
    23
    @heckubiss, the nature of a forum and because I don't know your level of PHP experience means I'm going one small step at a time. Alex has provided the next step above for a specific product.

    To generate a list of products, do a print_r() on the result of a get_products_list() query - this will probably produce an array of arrays - put it on this thread and someone can generate the code you need to display the list.

    Ian
  11. heckubiss

    heckubiss New Member

    Joined:
    Jun 6, 2004
    Messages:
    21
    Actually all I need is the price. Now I am trying to make a function so I dont have to have the above php code for every product I have. I just want to say show_price(22) and have it output the price.

    So for example I have a php file that looks like this

    <?php session_start(); ?>
    <html>
    <head>

    </head>
    <body >

    </body>
    </html>



    Do I have to wrap the whole file in <?php ?>
  12. heckubiss

    heckubiss New Member

    Joined:
    Jun 6, 2004
    Messages:
    21
    Never mind I figured it out.

    <?php
    include "amember/config.inc.php";
    function show_price($prod) {
    global $db;
    $p = $db->get_product($prod);
    print $p['price'] . '<br>';
    }
    ?>

    and when I want to find the price of the product I do

    <?php
    show_price(22);
    ?>

    for product 22 etc

    Thank you Ianh and Alex for your help. Now when I change my prices in aMember, they will automatically be reflected on my page without haveing to manually change them all :)

Share This Page