SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 66 of 66
  1. #51
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    OK, so could you post the PHP code that displays your blog posts please, and indicate where on the page you'd like to output the associated products.

  2. #52
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This the code for the blog. Unfortunately I cant change this as I dont products to be displays on every blog post.

    However actually I could do an else command but I dont if that is possible. I dont want the product display to be empty when I dont want to display products.

    Could and else option work?


    Code:
    <div class="articleborder">
    
    
    <div class="articletitleborder"><?php echo $row['title']; ?></div>
    <div class="articleintroborder"><h1><?php echo $row['intro']; ?> | <?php echo $row['articlecategory']; ?></h1></div>
    <div class="articlecontentborder"><?php echo $row['article']; ?></div>
    
    </div>

  3. #53
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    What about adding an extra field to your DB for product IDs that you want to associate with a given blog post? That way, when you query the DB to display the post, you can check if there are any associated products and display them alongside the post content.

  4. #54
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    What about adding an extra field to your DB for product IDs that you want to associate with a given blog post? That way, when you query the DB to display the post, you can check if there are any associated products and display them alongside the post content.
    That could work but when I dont want to display products I will be left with empty HTML.

    I could include the products from another page but I have had alot of problems when trying to include another page.

    Is there a stand code to include something?

  5. #55
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    That could work but when I dont want to display products I will be left with empty HTML.
    You can write your code in such a way that it only outputs the HTML when there are associated products products, something like this:

    PHP Code:
    <div class="articlecontentborder">
        <?php echo $row['article']; ?>
        <?php if ($row['associated_products']) {
            
    $products get_products_by_id(explode(','$row['associated_products']));
            foreach (
    $products as $product) { ?>
            <div>
                <?php echo $product->title ?>
                // ...
            </div>
        <?php }} ?>
    </div>

  6. #56
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That could work really well but I dont understand the code. Is it possible to say $linkname = mario.

    Would I swap $products with $linkname or does $products solve a pirticular solution?

  7. #57
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    That could work really well but I dont understand the code. Is it possible to say $linkname = mario.

    Would I swap $products with $linkname or does $products solve a pirticular solution?
    No it was just an example to show what I meant. Here's a more complete example, using some of the code from your first post:
    PHP Code:
    <?php

    // Blog query not shown

    $products = array();
    if (
    $row['associated_product'])
    {
        
    $query mysql_query("
        SELECT name, linkname, product_id, price, discount, image_link
            FROM productdbase p
            INNER JOIN furniture_groups f
                ON
                    f.id = p.id
            WHERE
                linkname LIKE '%
    $row[associated_product]%'
        LIMIT 15"
    );

        while (
    $query_row mysql_fetch_assoc($query)) {
            
    $products[] = $query_row;
        }
    }
    ?>

    <div class="articleborder">

        <div class="articletitleborder"><?php echo $row['title']; ?></div>
        <div class="articleintroborder"><h1><?php echo $row['intro']; ?> | <?php echo $row['articlecategory']; ?></h1></div>
        <div class="articlecontentborder"><?php echo $row['article']; ?></div>
        
        <?php foreach($products as $product): ?>
            <div class="productrangeborder">
                <div class="productsdetailsborder">
                    <a href="http://website.co.uk/products/product/<?php echo $product['product_id']; ?>" class='productlink' rel="nofollow" >
                        <?php echo $product['name']; ?>
                    </a>
                </div>

                <div class="productimageborder">
                    <a href="http://website.co.uk/products/product/<?php echo $product['product_id']; ?>" rel="nofollow">
                        <img src="<?php echo $product['image_link']; ?>" alt="<?php echo $product['name']; ?>" />
                    </a>
                </div>

                <div class="priceborder">Price <?php echo $product['price']; ?><br /></div>
                <div class="discountborder">Save <?php echo $product['discount']; ?>%<br /></div>
            </div>
        <?php endforeach; ?>

    </div>
    Edit: If there's any part of the code you'd like me to explain, just let me know

  8. #58
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I had a go at it. Linkname is the row I querying, What does your associated_product element mean?

    Code:
    <?php
    
    // Blog query not shown
    
    $products = array();
    if ($row['linkname'])
    {
        $query = mysql_query("
        SELECT name, linkname, product_id, price, discount, image_link
            FROM productdbase p
            INNER JOIN furniture_groups f
                ON
                    f.id = p.id
            WHERE
                linkname LIKE '%oak%'
        LIMIT 15");
    
        while ($query_row = mysql_fetch_assoc($query)) {
            $products[] = $query_row;
    		
    echo $row['price'];
    		
        }
    }
    
    echo $row['linkname'];
    
    ?>

  9. #59
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    I had a go at it. Linkname is the row I querying, What does your associated_product element mean?
    It's just an imaginary extra row on your blog post table, that would hold the link name that you'd use to search for related products to display, but you could call it anything you want obviously.

  10. #60
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Do I need to echo the the rows in a certain way. I currently cant display anything and there are no errors.

  11. #61
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Do I need to echo the the rows in a certain way. I currently cant display anything and there are no errors.
    Can you paste back the code for the blog page again, with the changes?

  12. #62
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This is the code I have:

    Code:
    $products = array();
    if ($row['linkname'])
    {
        $query = mysql_query("
        SELECT name, linkname, product_id, price, discount, image_link
            FROM productdbase p
            INNER JOIN furniture_groups f
                ON
                    f.id = p.id
            WHERE
                linkname LIKE '%oak%'
        LIMIT 15");
    
        while ($query_row = mysql_fetch_assoc($query)) {
            $products[] = $query_row;
    		
    echo $row['price'];
    		
        }
    }
    
    echo $row['linkname'];
    
    ?>

  13. #63
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    4 Thread(s)
    You put this code directly in the PHP file that displays the blog posts, right?

  14. #64
    SitePoint Evangelist bronze trophy
    Join Date
    Feb 2013
    Posts
    501
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    You put this code directly in the PHP file that displays the blog posts, right?
    Oh I sure hope so...

    Fretburner is pointing you in the right direction.
    Add a field to the table that holds your blog, which will store a comma separated list of keywords(products) related to the blog. He's exploding this line then using the foreach loop to display product. POST55

    OR a single item like POST 57

    Both ways will work.

    As we've both said, put the product display code on your blog page.

  15. #65
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    @justlukeyou ; how far have you got overall with this project, the reason I ask is that you need to seriously consider moving away from using the mysql_* extension as if you're using a server where you don't have control over what version of php is running, they could install at a later date the 5.6.x version of PHP that would supercede the current latest PHP version 5.5.x and. In the 5.6.x version the mysql_* extension will very likely not exist there so any script that relies on it would be broken.

    Also you should be making use of exceptions to handle errors, at the very least you should be monitoring the return values of functions that do things such as running a query to pick up on things like problems with a query, often they will return something different such as false for example if something went wrong.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  16. #66
    SitePoint Evangelist bronze trophy
    Join Date
    Feb 2013
    Posts
    501
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I "Second that motion" or in this case a statement of the realty of what's to come. Reworking a dozen pages isn't a big deal but redoing a completed project is a real pain. I have a huge project of 100 or so pages that I'm converting to PDO. Not fun. Guess that's why I've been visiting the the forum a lot, I need a break.


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
  •