?
Solved

wrong image shows when using two LIKE expressions

Posted on 2009-04-06
4
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

770 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