kosaks Posted January 11, 2012 Share Posted January 11, 2012 Hello to everyone I would like to ask for this simple question.. Im trying to put if and else condition on my php code. However this condition is not working.. if($file == #3#){ echo "No results found"; }else{ echo "results has been found"; } This variable $file is the result after i used an API.. If the API does not see any results they would return #3# as the result. This means they returned a transaction code of 3 which you can see here http://developer.textapp.net/WebService/TransactionCodes.aspx means that there was nothing to return. The condition does not function well even if i make 3 or #3# as part of the condition. Can you help me guys? thanks Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/ Share on other sites More sharing options...
trq Posted January 11, 2012 Share Posted January 11, 2012 #3# should cause you a syntax error as it makes absolutely no sense to php. You probably need to check for a string. if ($file == '#3#') { Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306366 Share on other sites More sharing options...
kosaks Posted January 11, 2012 Author Share Posted January 11, 2012 Hello.. Thanks for your help.. Sadly it does not solve my problem.. I've check the result again on the API and it returned #3# as the result.. However by using the if statement if($file == '#3#'){ echo "No results found"; }else{ echo "results has been found"; } the result is results has been found which is wrong the result should be No results found since my API does not see any result.. Does this has something to do with the returned string of my API? thanks Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306374 Share on other sites More sharing options...
trq Posted January 11, 2012 Share Posted January 11, 2012 What exactly is being returned and how? Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306380 Share on other sites More sharing options...
kosaks Posted January 11, 2012 Author Share Posted January 11, 2012 Hello sir This is actually being returned by the API #3# if it does not see any result. You can check it here http://developer.textapp.net/WebService/Methods_GetSMSInbound.aspx and for the transaction code #3# you can refer it here http://developer.textapp.net/WebService/TransactionCodes.aspx.. Dont know why the condition is not working.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306384 Share on other sites More sharing options...
trq Posted January 11, 2012 Share Posted January 11, 2012 We need to see code and exactly what your getting back as a response. Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306386 Share on other sites More sharing options...
kosaks Posted January 11, 2012 Author Share Posted January 11, 2012 Hello sir.. this is the code.. <?php $sc = new SoapClient('http://www.textapp.net/webservice/service.asmx?wsdl'); $params = new stdClass(); $params->returnCSVString = true; $params->externalLogin = 'SU11202050'; $params->password = 'jpdxcPK2'; $params->number = '+447537404702'; $params->keyword = 'test'; $result = $sc->__call('GetSMSInbound', array($params)); $file = $result->GetSMSInboundResult; if($file == '#3#'){ echo "No results found"; }else{ echo "results has been found"; } echo $file; ?> thanks Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306391 Share on other sites More sharing options...
trq Posted January 11, 2012 Share Posted January 11, 2012 What does: echo $file; output? Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306397 Share on other sites More sharing options...
kosaks Posted January 11, 2012 Author Share Posted January 11, 2012 yes sir.. it shows the output of the API.. Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306399 Share on other sites More sharing options...
trq Posted January 11, 2012 Share Posted January 11, 2012 Which is what exactly? I swear, this is the last time I'm going to ask this same question. Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306400 Share on other sites More sharing options...
kosaks Posted January 11, 2012 Author Share Posted January 11, 2012 Hello sir Sorry if you did not understand my reply. I myself is being puzzled on my work. When i use the API (Please refer to the API code earlier) it returns this as the output.. #1# "4","+447980987654","+447781537583","","2009-07-08","10:38:15","hello "","" world","Green" "5","+447980987654","+44776230146","","2009-07-08","10:38:55","hello world","Green" otherwise if it does have have any output to return.. this is the returned output of the API #3# Im thinking why my condition does not work well.. if i use this code for my condition.. if($file == '#3#'){ echo "No results found"; }else{ echo "results has been found"; } Does this makes sense sir? thanks Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306405 Share on other sites More sharing options...
kosaks Posted January 11, 2012 Author Share Posted January 11, 2012 Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306407 Share on other sites More sharing options...
Muddy_Funster Posted January 11, 2012 Share Posted January 11, 2012 what about making this change if(trim($file) == '#3#'){ Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306442 Share on other sites More sharing options...
MasterACE14 Posted January 11, 2012 Share Posted January 11, 2012 if(strpos($file, '#3#')){ echo "No results found"; }else{ echo "results has been found"; } Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306448 Share on other sites More sharing options...
kosaks Posted January 11, 2012 Author Share Posted January 11, 2012 Thanks guys.. My problem is solve now.. if(trim($file) == '#3#'){ echo "No results found"; }else{echo "results has been found"; } Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306477 Share on other sites More sharing options...
PFMaBiSmAd Posted January 11, 2012 Share Posted January 11, 2012 @MasterACE14, the logic you posted will fail to work when the '#3#' string is present and starts at position 0 in the variable. Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306479 Share on other sites More sharing options...
MasterACE14 Posted January 11, 2012 Share Posted January 11, 2012 ah true. Quote Link to comment https://forums.phpfreaks.com/topic/254779-a-simple-question/#findComment-1306688 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.