Hello guys. I'm having some trouble with a piece of code and if it is possible for you guys to take a look and detect what am I doing wrong with this I would appreciate it. I just cant found the error. I'll try to explain what I'm doing here.. so here it goes:
// I connect to Database
mysql_connect("localhost", "root","root") or die(mysql_error()) ;
mysql_select_db("thenNnow") or die(mysql_error()) ;
// I get this values from an external source ( Android ) which sends 2 strings and a JSON array
$data1 = $_POST['date1'];
$data2 = $_POST['date2'];
$JSONkeyword = $_POST['keyword'];
// Convert JSON keyword to a php array readable
$keyword = json_decode($JSONkeyword,*true);
[B]// CASE 1 - date 1 and 2 hand keywords had been set
[/B]if ($data1 != '0000-00-00' && $data2 != '0000-00-00' && empty($keyword) ==false) {
// Convert the date to Mysql readable
$firstdate = new DateTime($data1);
$date1=date_format ( $firstdate, 'Y-m-d' );
$seconddate = new DateTime($data2);
$date2=date_format ( $seconddate, 'Y-m-d' );
$bothparameter = "SELECT SP.ServicePic_ID, SP.ServicePic FROM Service_Pic SP, Keyword K, SPKeywords SPK, Date D WHERE SP.ServicePic_ID=SPK.ServicePic_ID AND SPK.Keyword_ID=K.Keyword_ID AND SP.Date_ID=D.Date_ID AND D.Date BETWEEN '$date1' AND '$date2' AND K.Keyword IN ('" . implode("','", $keyword) . "')";
$result=mysql_query($bothparameter);
if (!$result) {
echo 'Could not run query bothparameters!' . mysql_error();
exit;
}$row=mysql_fetch_row($result);
[B]// CASE 2 - Dates have been set but no keywords
[/B]} elseif ($data1 != '0000-00-00' && $data2 != '0000-00-00' && empty($keyword)== true) {
// Convert the date to Mysql readable
$firstdate = new DateTime($data1);
$date1=date_format ( $firstdate, 'Y-m-d' );
$seconddate = new DateTime($data2);
$date2=date_format ( $seconddate, 'Y-m-d' );
$dateparameter="SELECT SP.ServicePic_ID, SP.ServicePic FROM Service_Pic SP, Date D WHERE SP.Date_ID=D.Date_ID AND D.Date BETWEEN '$date1' AND '$date2'";
$result=mysql_query($dateparameter);
if (!$result) {
echo 'Could not run query dateparameter!' . mysql_error();
exit;
}$row=mysql_fetch_row($result);
[B]// CASE 3 - No dates have been set
[/B]} elseif ($data1 == '0000-00-00' || $data2 == '0000-00-00' && empty($keyword) == false) {
$keywordparameter="SELECT SP.ServicePic_ID, SP.ServicePic FROM Service_Pic SP, Keyword K, SPKeywords SPK WHERE SP.ServicePic_ID=SPK.ServicePic_ID AND SPK.Keyword_ID=K.Keyword_ID AND K.Keyword IN ('" . implode("','", $keyword) . "')";
$result=mysql_query($keywordparameter);
if (!$result) {
echo 'Could not run query!' . mysql_error();
exit;
}$row=mysql_fetch_row($result);
}
// If there's no Picture name ( Sp.ServicePic ) it creates this Array
if (empty($row[1]) == true){
$array = array(error=>"empty");
$jsontosend = json_encode($array);
}else{
// else it does all this queries and creates the array anyway
$getposition="SELECT P.GPSLatitude, P.GPSLongitude, P.GPSLatitudeRef, P.GPSLongitudeRef FROM Service_Pic SP, Position P WHERE SP.Position_ID=P.Position_ID AND SP.ServicePic_ID=$row[0]";
$positionresult=mysql_query($getposition);
if (!$positionresult) {
echo 'Could not run query!' . mysql_error();
exit;
}$positiondata=mysql_fetch_row($positionresult);
$getorientation="SELECT O.GPSImgDirection, O.GPSImgDirectionRef FROM Service_Pic SP, Orientation O WHERE SP.Orientation_ID=O.Orientation_ID AND SP.ServicePic_ID=$row[0]";
$orientationresult=mysql_query($getorientation);
if (!$orientationresult) {
echo 'Could not run query!' . mysql_error();
exit;
}$orientationdata=mysql_fetch_row($orientationresult);
// Save pic link on variable
$pic = 'http://www.pedroteixeira.org/thennnow/images/'.$row[1].'.png';
// Encode everything in a JSON array
$array = array(picture=>$pic, latitude=>$positiondata[0], latitudeRef=>$positiondata[2], longitude=>$positiondata[1], longitudeRef=>$positiondata[3], orientation=>$orientationdata[0], orientationRef=>$orientationdata[1]);
$jsontosend = json_encode($array);
}
// Send this header back to Android where I can use the JSON format
header("Content-type: application/json");
print $jsontosend;
exit;
?>
Ok so the thing is.. Case 1 and 2 working fine... Case 3, where there's no dates just keywords it's returning me a <br/> in Android and I have no idea why.. it should do what the others do.. Send an array with all that information or an array with that error message... The thing is I run a PHP debugger and works fine there.. but not in Android.. all the other cases are right.. can you check it please? some language mistake or something ?
Thank you very much for your time. Hope you can help