SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Joining Tables fields display issues

    PHP Code:
    <?php
    $dynamicList 
    "";
    $sqlmysql_query("SELECT products.product_name,products.price,products.subcategory,products.location,products.date_added, products.category,
    products.id,categories.id,categories.category  FROM products,categories ORDER BY date_added DESC LIMIT 6"
    );
    $productCount mysql_num_rows($sql); 
    if (
    $productCount>)
         {
            
                        
    $id$row["id"];
                        
    $product_name$row["product_name"];
                        
    $price $row["price"];
                        
    $category $row["category"];
                        
    $subcategory $row["subcategory"];
                        
    $location $row["location"];
                        
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
                       
    $dynamicList .= ' <div>' $category'</div>'
    }
    ?>

    How can I display the content on categories.category inside the $category variable? instead the $dynamicList variable is containing the products.category field content when it is displayed in the <div> tags.

  2. #2
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    You will need a while() loop.
    PHP Code:
    $sqlmysql_query("SELECT products.product_name,products.price,products.subcategory,products.location,products.date_added, products.category, products.id,categories.id,categories.category  FROM products,categories ORDER BY date_added DESC LIMIT 6");
    while(
    $row mysql_fetch_assoc($sql)){
       
    // loop variables
       
    echo $row['product_name']." ".$row['price'];

    Ryan B | My Blog | Twitter


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
  •