1

I have a table1 named 'residencial' and table2 named 'propert_data'.

In 'residencial' table, I have a column named 'main_cat' which can have 3 values i.e 'Residential', 'Commercial' and 'Land'.

I have 2 web services named commercial_data.php and residential_data.php

1) commercial_data.php:

<?php
require 'include/connection.php';

$sql="SELECT * FROM residencial INNER JOIN propert_data ON propert_data.r_id = residencial.pid WHERE residencial.main_cat= 'Commercial' AND propert_data.meta_key = 'slider_images'";

 $rows = array();
 $result = mysqli_query($conn, $sql);

while($row = mysqli_fetch_assoc($result)) {
    array_push($rows,$row);
}
$myJson = json_encode($rows);
echo $myJson;

?>

Output of this is perfect.

2) residential_data.php:

<?php
require 'include/connection.php';

$sql="SELECT * FROM residencial INNER JOIN propert_data ON propert_data.r_id = residencial.pid WHERE residencial.main_cat= 'Residential'
    AND propert_data.meta_key = 'slider_images'";

 $rows = array();
 $result = mysqli_query($conn, $sql)or die(mysqli_error($conn));

while($row = mysqli_fetch_assoc($result)) {

    array_push($rows,$row);
}

$myJson = json_encode($rows);

echo "Data:". $myJson;

?>

Output of this is: Data:

The only difference in two file is:

In file 1, I have: residencial.main_cat = 'Commercial'

In file 2, I have: residencial.main_cat = 'Residential'

What could the problem be?

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • 1
    Do you get any errors? Have you tried debugging your code? Are there faults in your table structure which prevents it to be correctly encoded to JSON? From the looks of it, your code seems alright but you need to debug it. Read [this](https://stackoverflow.com/questions/5710665/how-to-debug-php-code) – Sanguinary Oct 12 '18 at 06:30
  • Thanks will see if it works.. – Akash Bisht Oct 13 '18 at 11:41
  • `$sql="SELECT * FROM residencial INNER JOIN propert_data ON propert_data.r_id = residencial.pid WHERE residencial.main_cat= 'Residential' AND propert_data.meta_key = 'slider_images'";` does this query have result in phpmyadmin? – Beginner Oct 19 '18 at 03:46
  • Yes it works perfectly fine in phpmyadmin.. – Akash Bisht Oct 19 '18 at 10:46

1 Answers1

-1

You can Use like this:

while($row = mysqli_fetch_object($result)) {
  $rows[] = $row;
}
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Palash
  • 9
  • 3