[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

wrong image shows when using two LIKE expressions

Posted on 2009-04-06
4
Medium Priority
?
169 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:Richard Davis
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:
Richard Davis earned 2000 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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

834 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