Solved

mysql if sentence

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now