Solved

wrong image shows when using two LIKE expressions

Posted on 2009-04-06
4
160 Views
Last Modified: 2013-12-12
Hello

When I use two expressions to pick out a list of product codes from a database then display them with an image I get the wrong image showing. I have a noimage.gif which displays correctly if I use the expression on its own.

here's the code: I am picking out XST, XPV, XUT and XC. if I do it individually it works. the code for displaying in at the bottom.
$q= "SELECT products.product_id, products.stock_indicator, products.size_number, products.size_desc, products.description, products.trade_price_single, products.trade_price_multi, images.path FROM products, images  WHERE products.product_id LIKE 'XST%' OR products.product_id LIKE 'XPV%' OR products.product_id like 'XUT%' OR products.product_id like 'XC%' AND products.product_id=images.product_id GROUP BY products.product_id ORDER BY products.product_id ASC LIMIT $start,$display";
 
code for displaying the product image
 
echo '	<div class="imagebox"><img src=../praybourne/'. $row['path'] . '></div>';

Open in new window

0
Comment
Question by:Skycapt
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:adrian_brooks
ID: 24083257
Have you confirmed that your product_id fields match in both the products & images table?

Sounds like you have something mismatched.

~A~
0
 
LVL 1

Author Comment

by:Skycapt
ID: 24084851
Hi Adrian

As far as I can tell they match, the funny thing is if I use the expression on its own such as 'XST%' it pulls the correct image and shows correctly, when I couple two expressions together such as XST OR XPV it seems to pick a random image and display that for each row.

Do you need to see the data file?
0
 
LVL 12

Accepted Solution

by:
adrian_brooks earned 500 total points
ID: 24088350
Try surrounding all your OR conditions in parentheses to separate them from your AND condition.
SQL is a rather fickle language in that respect.

So, instead of your existing SQL SELECT statement, perhaps try this;


Something else worth bringing up here though would be, does the images table have multiple images per record that the OR clause would get confused on? Let's assume that each record in the images table can have one or more of those prefixes. When that OR condition is processed, then it will find multiple TRUE conditions and likely return the last known positive match.

~A~
$q= "SELECT products.product_id, products.stock_indicator, products.size_number, products.size_desc, products.description, products.trade_price_single, products.trade_price_multi, images.path FROM products, images  WHERE (products.product_id LIKE 'XST%' OR products.product_id LIKE 'XPV%' OR products.product_id like 'XUT%' OR products.product_id like 'XC%') AND products.product_id=images.product_id GROUP BY products.product_id ORDER BY products.product_id ASC LIMIT $start,$display";

Open in new window

0
 
LVL 1

Author Closing Comment

by:Skycapt
ID: 31567284
Hi Adrian

That worked! Thanks very much
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question