Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3497424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:22:07+00:00 2026-05-18T12:22:07+00:00

this site is like an ecommerce site and i have two tables that i’m

  • 0

this site is like an ecommerce site and i have two tables that i’m stuck on.

tbl_products
---------------
phash
product
price
desc
maxcount


tbl_product_images
-------------------
phash
thumb
large

tbl_products stores the products description
tbl_product_images stores the path of the thumb and large image of eac product.

phash is an md5 of the products name its what i use rather than the id or product name when matching things together.

what i’m having throuble with is say tbl_products has one record for a product and tbl_product_images
in relation to that product has 5 rows for its images.

how would i run the query?

$sql = "select
    tbl_products.phash
    tbl_products.product
    tbl_products.price
    tbl_products.desc
    tbl_products.maxcount
    tbl_product_images.phash
    tbl_product_images.thumb
    tbl_product_images.large
    from tbl_products
    inner join tbl_product_images
    on tbl_products.phash = tbl_products_images.phash";

this will display 5 rows of records since tbl_product_images has 5 records.

the way i output is my traditional way

$query = $db->query("$sql");
while($row = $db->fetch($query))
{
....

}

i am really unsure how i’m going to do this, if you need more explanation to what i’m trying to explain please let me know. thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:22:08+00:00Added an answer on May 18, 2026 at 12:22 pm

    The simplest way is to limit the number of results coming from the images table – though that’s only appropriate if you don’t care which image is returned for each product:

    select
        tbl_products.phash
        tbl_products.product
        tbl_products.price
        tbl_products.desc
        tbl_products.maxcount
        tbl_product_images.phash
        tbl_product_images.thumb
        tbl_product_images.large
        from tbl_products
        inner join (SELECT * FROM tbl_product_images LIMIT 1) images
        on tbl_products.phash = images.phash
    

    You can add an ORDER BY [col] DESC to that LIMITed query if there’s some other column in the images table (like a date) you could use to determine which image appears.

    (Note: If there were some column in tbl_product_images that determined which image to return, you could either put that in a WHERE clause on the query, or include it in the join criteria, like: ON tbl_products.phash = tbl_product_images.phash AND tbl_product_images.color = 'Blue')

    Further, if you are trying to get a product with all of its images, but only want one row in the resultset, it may be possible to “pivot” the set of images into columns. However, this is tricky if you can have an arbitrary (or simply large) number of images per product. You may be better off just returning multiple rows per product, and handling the results in your application code…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ecommerce site which currently has product URLs like this: http://www.mydomain.com/nike-tshirt/Large http://www.mydomain.com/nike-tshirt/Medium
First I would like to say that I am new to this site, never
I have a web site like this: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title></title> <link rel=stylesheet type=text/css
I saw a website today that stated: Share/Like this site and get 10% discount.
I run a ecommerce site, and I have tons of product images. The naming
I have eCommerce site. I have product page where you can pick up different
I copy a script of Kevin S (member of this site) like this <table
Like this site Pay attention to your address bar.
I wasnt to make something like this site where I can scroll up and
I'm developing a site which has urls like this: site.com/james site.com/james/photos Schema for this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.