Solved

mysql if sentence

Posted on 2011-02-14
3
330 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
  • 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checking CSRF token within a function 36 74
php convert date format 3 21
write screen output to text file 21 47
mysql date time 14 28
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

786 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