phpmyadmin problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

street_spirit
Forum Newbie
Posts: 11
Joined: Tue Apr 28, 2009 11:43 am

Re: phpmyadmin problem

Post by street_spirit »

From what I can see that displays multiple images just not sure I get the link of how it works out which images go with which products if you get me? Sorry drawing a real blind spot on all of this stuff.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: phpmyadmin problem

Post by McInfo »

The original table structure allowed each product to have only one image. Because the product and its image had a one-to-one relationship, it was acceptable to treat the image as an attribute of the product (as a field in the product table).

You wanted each product to have one or more images. If the number of images is unknown, the image must become a separate entity and have its own table. This is because, in a relational database, the number of rows|records|tuples expands but the number of columns|fields|attributes remains the same.

In the tbl_product table, each product is identified by a unique number (pd_id). This number also appears in the tbl_product_image table so that many images can be related to a single product.

In PHP, where a product image was previously treated as a single string...

Code: Select all

Array
(
    [pd_name] => Example Product
    [pd_description] => This is an example product.
    [pd_price] => 0.12
    [pd_qty] => 1
    [pd_image] => /plaincart/images/product/94cd0cb73dc8bae134bbad9664d841f1.jpg
    [cart_url] => cart.php?action=add&p=22
)
...it must now be treated as an array of strings.

Code: Select all

Array
(
    [pd_name] => Example Product
    [pd_description] => This is an example product.
    [pd_price] => 0.12
    [pd_qty] => 1
    [pd_image] => Array
        (
            [0] => /plaincart/images/product/94cd0cb73dc8bae134bbad9664d841f1.jpg
            [1] => /plaincart/images/product/94cd0cb73dc8bae134bbad9664d841f1.jpg
        )
    [cart_url] => cart.php?action=add&p=22
)
To make debugging easier, open library/product-functions.php and replace

Code: Select all

    return $row;
with

Code: Select all

    file_put_contents('debug-log-getProductDetail.txt', print_r($row, 1));
   
    return $row;
Edit: This post was recovered from search engine cache.
Post Reply