Solved

mysql if sentence

Posted on 2011-02-14
3
333 Views
Last Modified: 2012-05-11
Dear Experts,
is there a way to merge this two sql statement?

              if (!empty($company))
      {
      $sqlsentence. = " and Company1 like '" . $company . "%'"
      }
        
                      if (!empty($company))
      {
      $sqlsentence. = " and Company2 like '" . $company . "%'"
      }
      
$mysqlsentence= "SELECT * FROM Mytable where 1=1" . $sqlsentence ";
0
Comment
Question by:Braveheartli
[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
3 Comments
 
LVL 1

Author Comment

by:Braveheartli
ID: 34886583
would it be correct to write it like this?

$sqlsentence. = " and Company1 like '" . $company . "%' and Company2 like '" . $company . "%'"
0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 500 total points
ID: 34886864
Yes.
if (!empty($company)){
 $sqlsentence. = " and Company1 like '" . $company . "%' and Company2 like '" . $company . "%'";
}
0
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 34887012
thank you very much
0

Featured Post

Technology Partners: 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

This article discusses how to implement server side field validation and display customized error messages to the client.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

635 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