[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

wrong image shows when using two LIKE expressions

Posted on 2009-04-06
4
Medium Priority
?
167 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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

650 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