SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26
  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    image_url - Won't show picture

    I have setup a basic shop feature.

    I want the look to display the picture of the product from the info page.

    The problem I am getting is the image will not show on the products page, only the product info page.

    Code:
    <a href="<?php echo get_url('/products/', $category_id, $product['product_id'], $product['product_name']); ?>"><img src="/images/products/thumbnails/<?php echo $product['image_url']; ?>" border="0" alt="<?php echo $product['product_name']; ?>" title="<?php echo $product['product_name']; ?>" /></a>
    This is the code that I am using.

    Does anyone know why this could be, or what I am doing wrong?

    I assumed that it's just a case of using the 'image_url' function any where as it all relates to one place?

    Any help would be greatly welcomed.

    Cheers,

    Paul

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can you post the html outputted on each of that 'pages' in question? i.e. img tag etc.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not 100&#37; sure what you are asking for but here is all the HTML for the page.

    PHP Code:
    <h1><?php echo array_key_exists($category_id$categories) ? $categories[$category_id]['category_name'] : 'Products'?></h1>
    <?php if (array_key_exists(3$list_categories) && array_key_exists($category_id$list_categories[3])) { ?>
    <div>
      <ul>
        <?php foreach ($list_categories[3][$category_id] as $category) { ?>
        <li><a href="<?php echo get_url('/products/'$category['category_id']); ?>"><?php echo $category['category_name']; ?></a></li>
        <?php ?>
      </ul>
    </div>
    <?php ?>
    <br />
    <div align="right"><?php echo multipage(get_num_products($category_id), PRODUCTS_MAX_NUM$page$category_id == '/products/' get_url('/products/'$category_id)); ?></div>
    <table class="tableGrid">
      <tr>
        <th>&nbsp;</th>
        <th>Product</th>
        <th>Price</th>
        <th>&nbsp;</th>
      </tr>
      <?php $counter 0?>
      <?php foreach (get_products($category_id$page) as $product) { ?>
        <tr>
          <td><a href="<?php echo get_url('/products/'$category_id$product['product_id'], $product['product_name']); ?>"><img src="/images/products/thumbnails/<?php echo $product['image_url']; ?>" border="0" alt="<?php echo $product['product_name']; ?>" title="<?php echo $product['product_name']; ?>" /></a></td>
          <td><a href="<?php echo get_url('/products/'$category_id$product['product_id'], $product['product_name']); ?>"><?php echo $product['product_name']; ?></a><br /><br />
          <?php echo strlen($product['description']) > 150 substr($product['description'], 0150) . '...' $product['description']; ?>
          </td>
          <td align="center"><strong><?php echo get_price($product['price']); ?></strong></td>
          <td><a href="/cart/index.htm?action=add_product&amp;product_id=<?php echo $product['product_id']; ?>"><img src="<?php echo '/' $config['image_path']; ?>button_cart_add.gif" border="0" alt="Add to Shopping Basket" title="Add to Shopping Basket" /></a></td>
        </tr>
        <?php $counter++; ?>
      <?php ?>
    </table>
    <div>
    </div>
    <div align="right"><?php echo multipage(get_num_products($category_id), PRODUCTS_MAX_NUM$page$category_id == '/products/' get_url('/products/'$category_id)); ?></div>
    I think I might need to implement this code below into somewhere but I am not 100% sure, I have tried various different ways but it interferes with other code and causes errors.

    PHP Code:
    <?php if ($product['image_url'] != '' && file_exists(ROOT_PATH 'images/products/thumbnails/' $product['image_url'])) { ?>
            <?php ?>

  4. #4
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,364
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    What SilverBulletUK wants to know is when you right click the missing image what is the path to the image in Address(URL)

  5. #5
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah ok, it is:

    "http://test.localhost/images/products/thumbnails/&#37;3Cbr%20/%3E%3Cb%3ENotice%3C/b%3E:%20%20Undefined%20index:%20%20image_url%20in%20%3Cb%3EC:/Hosting/Test/templates/products/index.tpl.php%3C/b%3E%20on%20line%20%3Cb%3E23%3C/b%3E%3Cbr%20/%3E"

    Cheers,

    Paul

  6. #6
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,364
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    So there is a problem with line 23 in file index.tpl.php
    http://test.localhost/images/products/thumbnails/<br /><b>Notice</b>: Undefined index: image_url in <b>C:/Hosting/Test/templates/products/index.tpl.php</b> on line <b>23</b><br />

  7. #7
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what is on line 23, I can't see the error. It has worked fine before.

    <td><a href="<?php echo get_url('/products/', $category_id, $product['product_id'], $product['product_name']); ?>"><img src="/images/products/thumbnails/<?php echo $product['image_url']; ?>"

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    It's saying that the $product array doesn't have an image_url element.

    Try var_dump'ing the $product array to see if it contains what you expect.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  9. #9
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,364
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    Do you have a database column called image_url?

    What I tend to do is echo the variables to confirm what they contain and take them out later:
    PHP Code:
    echo "product_id = ".$product['product_id']."<br>";
    echo 
    "product_name = ".$product['product_name']."<br>";
    echo 
    "image_url = ".$product['image_url']."<br>"
    Out of interest are you supressing your mysql queries with a @ if so remove them until you get your code working.

  10. #10
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, both of you are probably right, but as I am new to learning PHP I don't fully understand.

    How would I go about 'var_dump' the $product array?

    Many thanks,

    Paul

  11. #11
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Spot the first use $product in the code, then in the line before it, pop in...
    var_dump($product);

    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  12. #12
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have tried that and I get this error:

    Notice: Undefined variable: product in C:\Hosting\Test\templates\products\index.tpl.php on line 21
    NULL

  13. #13
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Put the var_dump after this line if you wouldn't mind.
    <?php foreach (get_products($category_id, $page) as $product) { ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  14. #14
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, that has come up with something, I am assuming it is meant to be some text saying what is there:

    array(4) { ["product_id"]=> string(1) "2" ["product_name"]=> string(13) "Playstation 2" ["description"]=> string(177) "At the heart of the PlayStation 2 is the 128-bit Emotion Engine processor, which combines lightning-fast gameplay and unprecedented graphics power with DAT-quality stereo sound." ["price"]=> string(7) "49.0000" }
    array(4) { ["product_id"]=> string(1) "1" ["product_name"]=> string(18) "Sony Playstation 3" ["description"]=> string(447) "The PlayStation 3 computer entertainment system unleashes a brilliant, high-definition entertainment experience with its Cell Broadband Engine that delivers a gaming experience that is beyond what you know today. Its built-in Blu-ray Disc drive delivers a whole new generation in high-definition gaming and unmatched digital media storage. Whether itís gaming, Blu-ray movies, music or online services, PlayStation 3 will change your digital life." ["price"]=> string(8) "299.0000" }
    Is this is what supposed to happen?

    Cheers

  15. #15
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, that has come up with something, but it will not let me post it on this forum. Says "The following errors occurred with your submission" but it doesn't show any errors.

    http://new.freelance-creator.com/error.txt - You can find what it says here.

    Cheers

  16. #16
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    As suspected, the product array does not contain a image_url element. You may need to take another look at the get_products function.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  17. #17
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, the image works on the Information page of the product and it has this line:

    <?php if ($product['image_url'] != '' && file_exists(ROOT_PATH . 'images/products/thumbnails/' . $product['image_url'])) { ?>
    Do I need to implement that into:

    <?php foreach (get_products($category_id, $page) as $product) { ?>
    Or is it a case of I have completed bullsed it up?

    Many thanks,

    Paul

  18. #18
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    On the information page, how is the $product array obtained? Using the same get_products function?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  19. #19
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the page it all relates to with functions:

    <?php

    define('ROOT_PATH', './../');
    require ROOT_PATH . 'includes/common.inc.php';

    $tpl = new template(ROOT_PATH . $config['template_path']);
    $body = new template(ROOT_PATH . $config['template_path'] . 'products/');

    $category_id = isset($_GET['category_id']) && is_numeric($_GET['category_id']) ? (int) $_GET['category_id'] : 0;

    $tpl->set('title', (array_key_exists($category_id, $categories) ? $categories[$category_id]['category_name'] : 'Products') . ' - ' . $config['site_name']);
    $tpl->set('description', array_key_exists($category_id, $categories) ? $categories[$category_id]['description'] : '');
    $tpl->set('keywords', array_key_exists($category_id, $categories) ? $categories[$category_id]['keywords'] : '');
    $tpl->set('navigation', '<a href="/">Home</a> &raquo; ' . ($category_id == 0 ? 'Products' : '<a href="/products/">Products</a> &raquo; ') . implode(' &raquo; ', get_navigation(3, $category_id, '/products/')));

    /**
    * get_num_products() - get the number of products in a category
    *
    * @param $category_id integer, category id
    * @return integer, number of products
    */
    function get_num_products($category_id) {
    $result = $GLOBALS['db']->query("SELECT COUNT(product_id) FROM " . $GLOBALS['config']['db']['prefix'] . "products WHERE category_id = $category_id AND status = 1");
    return $GLOBALS['db']->result($result, 0);
    }

    /**
    * get_products() - get the products in a category
    *
    * @param $category_id integer, category id
    * @param $page integer, current page
    * @return array, products
    */
    function get_products($category_id, $page) {
    $result = $GLOBALS['db']->query("SELECT product_id, product_name, description, price FROM " . $GLOBALS['config']['db']['prefix'] . "products WHERE category_id = $category_id AND status = 1 ORDER BY display_order, product_name LIMIT " . ($page - 1) * PRODUCTS_MAX_NUM . ", " . PRODUCTS_MAX_NUM);
    return fetch_array($result);
    }

    $body->set('category_id', $category_id);
    $body->set('page', isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1);
    $tpl->set('body', $body->fetch('index.tpl.php'));
    echo $tpl->fetch('layout.tpl.php');

    ?>
    I am not sure what to look for with regards to this. Cheers

  20. #20
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well, I guess, you *could* just replace the function with...
    PHP Code:
    <?php
    /**
    * get_products() - get the products in a category
    *
    * @param $category_id integer, category id
    * @param $page integer, current page
    * @return array, products
    */
    function get_products($category_id$page) {
    $result $GLOBALS['db']->query("SELECT product_id, product_name, description, price, image_url FROM " $GLOBALS['config']['db']['prefix'] . "products WHERE category_id = $category_id AND status = 1 ORDER BY display_order, product_name LIMIT " . ($page 1) * PRODUCTS_MAX_NUM ", " PRODUCTS_MAX_NUM);
    return 
    fetch_array($result);
    }
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  21. #21
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fantastic, that works a charm. I have another issue now though, now the image is showing perfect, but on the info.tpl.php file (which shows the product itself) is producing an error:

    Parse error: syntax error, unexpected '}' in C:\Hosting\Test\templates\products\info.tpl.php on line 8

  22. #22
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can you post the tpl?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  23. #23
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the \templates\products\info.tpl.php code:

    <table border="0" cellpadding="3" cellspacing="1" width="100&#37;">
    <tr>
    <?php if ($product['image_url'] != '' && file_exists(ROOT_PATH . 'images/products/thumbnails/' . $product['image_url'])) { ?>
    <?php } ?>
    <td rowspan="5" valign="top" width="20%"><p><a href="/images/products/<?php echo $product['image_url']; ?>" target="_blank"><img src="/images/products/thumbnails/<?php echo $product['image_url']; ?>" border="0" alt="<?php echo $product['product_name']; ?>" title="<?php echo $product['product_name']; ?>" /><br />
    Click to enlarge</a></p>
    </td>
    <?php } ?>
    <td width="60%"><h1><?php echo $product['product_name']; ?></h1></td>
    <td rowspan="5" valign="top" width="20%"><div class="main_box">
    <h2>Rate Product</h2>
    <form method="post" action="<?php echo get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']); ?>?action=rate">
    <input type="hidden" name="info_id" value="<?php echo $product['product_id']; ?>" />
    <select name="rating">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>
    <input type="submit" name="submit" value="Go!" />
    </form>
    </div></td>
    </tr>
    <tr>
    <td width="70%">Price: <?php echo get_price($product['price']); ?></td>
    </tr>
    <tr>
    <td width="70%">Availability: <span class="important"><?php echo $product['stock'] > 0 ? 'Available' : 'Not Available'; ?></span></td>
    </tr>
    <tr>
    <td width="70%">Rating: <?php echo $product['num_votes'] != 0 ? rating($product['rating'], $product['num_votes']) . ' (no. of votes: ' . $product['num_votes'] . ')' : 'Not Rated'; ?></td>
    </tr>
    <tr>
    <td width="70%">Date Added: <?php echo gmdate($user_data['date_format'], $product['date_created'] + ($user_data['time_offset'] * 3600) + ($config['add_time'] * 3600)) . ' at ' . gmdate($user_data['time_format'], $product['date_created'] + ($user_data['time_offset'] * 3600) + ($config['add_time'] * 3600)); ?></td>
    </tr>
    <tr>
    <td colspan="3"><?php echo check_output($product['content'], true, false, false); ?></td>
    </tr>
    </table>
    <p align="center"><a href="/cart/index.htm?action=add_product&amp;product_id=<?php echo $product['product_id']; ?>"><img src="<?php echo '/' . $config['image_path']; ?>button_cart_add.gif" border="0" alt="Add to Shopping Basket" title="Add to Shopping Basket" /></a></p>
    <div>
    <h2>Reviews</h2>
    <?php $counter = 0; ?>
    <?php foreach (get_reviews($product['product_id'], $page) as $review) { ?>
    <?php echo $counter != 0 ? '<hr />' : ''; ?>
    <?php echo $review['username']; ?> - <?php echo gmdate($user_data['date_format'], $review['date_created'] + ($user_data['time_offset'] * 3600) + ($config['add_time'] * 3600)) . ' at ' . gmdate($user_data['time_format'], $review['date_created'] + ($user_data['time_offset'] * 3600) + ($config['add_time'] * 3600)); ?><br />
    <?php echo $review['review']; ?>
    <?php $counter++; ?>
    <?php } ?>
    </div>
    <?php echo multipage(get_num_reviews($product['product_id']), 15, $page, get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']) . '?page='); ?>
    <br />
    <br />
    <form method="post" action="<?php echo get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']); ?>?action=review">
    <input type="hidden" name="info_id" value="<?php echo $product['product_id']; ?>" />
    <div class="main_box">
    <h2>Review Product</h2>
    <table border="0" cellpadding="3" cellspacing="1">
    <tr>
    <td valign="top">Review/td>
    <td><textarea name="review" cols="30" rows="5"></textarea></td>
    </tr>
    </table>
    </div>
    <p align="center"><input type="submit" name="submit" value="Submit Review" /></p>
    </form>
    Cheers

  24. #24
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ok, lose the bolded line and give that a go fella.

    <?php if ($product['image_url'] != '' && file_exists(ROOT_PATH . 'images/products/thumbnails/' . $product['image_url'])) { ?>
    <?php } ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  25. #25
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wahey, it works a peach !!! .. Thank you very much for your help!

    I am hoping I can progress with PHP rapidly as I get frustrated with myself for not knowing stuff.

    Again many thanks, you are an absolute star!


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
  •