Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mysql if sentence

Posted on 2011-02-14
3
Medium Priority
?
336 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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