-3

How to use two AND operators in MySQLi query?

$query = "select * from agent_profile where status=1";
       $run = mysqli_query($con,$query);
       $fetchdata = mysqli_fetch_array($run);
       $crnt_id = $fetchdata['agent_id'];
       if (mysqli_num_rows($run) > 0){

       $pricequery = "select * from airport_parking where (agent_id = '$crnt_id') AND (airport_name = '$airport') AND  ('$parking_start_time' >= start_time) ";
       $resultprice = mysqli_query($con,$pricequery);
       if( mysqli_num_rows($resultprice) > 0){
       $squery = "select * from agent_services where agent_id = '$crnt_id' AND service_type= '$service_type' ";
       $srun = mysqli_query($con,$squery);


 if( mysqli_num_rows($srun) > 0 ){

            while (($datarow = mysqli_fetch_array($run)) AND  ($getdata = mysqli_fetch_array($resultprice)))
           {
Dave
  • 5,108
  • 16
  • 30
  • 40
Rayn
  • 1
  • 4
  • What errors/issues are you facing? You are using `AND` correctly – B001ᛦ Apr 16 '19 at 10:46
  • 1
    Nothing wrong with how u use AND.. just check for mysqli errors. [How to get MySQLi error information in different environments](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-information-in-different-environments) – Masivuye Cokile Apr 16 '19 at 10:47
  • There is no error but the desired result is not showing – Rayn Apr 16 '19 at 10:47
  • _desired result is not showing..._ Post the **relevant** part of the code as you are here not trying to "show" anything – B001ᛦ Apr 16 '19 at 10:48
  • Post your db schema and desired results and the results u getting @Rayn – Masivuye Cokile Apr 16 '19 at 10:48
  • Check now my question – Rayn Apr 16 '19 at 10:49
  • `$run` is not equal to `$srun` and there should not be an `AND` in your `WHILE` loop definition. – Jay Blanchard Apr 16 '19 at 10:50
  • [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Apr 16 '19 at 10:52
  • Actually, I want to make a filter in which three conditions. 1st is company status must be 1 after that show that company which provide the same airport and start time and last condition is service is equal to user search. – Rayn Apr 16 '19 at 10:55
  • You cannot do that until you fix your code. – Jay Blanchard Apr 16 '19 at 10:55
  • So tell me how to do this? – Rayn Apr 16 '19 at 10:57
  • Remove the `AND` from your `while()` loop. – Jay Blanchard Apr 16 '19 at 11:02
  • Ok then what can I use in while loop? – Rayn Apr 16 '19 at 11:05
  • It would be hard to tell, because I don't know what your logic is. You have not explained what you're trying to do. – Jay Blanchard Apr 16 '19 at 11:09

1 Answers1

-3

Try this

$pricequery = "select * from airport_parking where (agent_id = '".$crnt_id."strong text') AND (airport_name = '".$airport."') AND  ('".$parking_start_time."' >= start_time) ";
Vansh Tah
  • 153
  • 8
  • 3
    Do or do not. There is no "try". A ***good answer*** will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO. What you've done here makes no difference. – Jay Blanchard Apr 16 '19 at 10:51