tags:

views:

111

answers:

3

Why is showphp_Smartfm() Not echoing at all.

  foreach($response->quizzes as $quiz)
        {
          echo $quiz->question; // not echoing
          echo $quiz->answer; // not echoing
        }

Followup Question to http://stackoverflow.com/questions/2116963/navigating-objects-and-arrays http://github.com/klanestro/Vortoj

<html>
<body>

<?php
// Created by Talisman 01/2010 ★✩ 

$vorto = $_GET['vorto']; // Get the Word from Outer Space and Search for it!




if (isset($vorto))
    {
    echo " Your Direct search was " . $vorto .  ' <br></br> '; 
    } else {
        $Help = "No Vorto -> add ?vorto=TheWordYouWant to the end of this website";
        echo $Help;
    }



// Now Lets Search Alex's Vortaro, It uses jsonp
//  ex. http://vortaro.us.to/ajax/epo/eng/petas/?callback=?

/* Future Feature inproved language functinality */

// I used the capital AV to denote variables belonging to Alex's Vortaro
// #Plans for ( traduku.net, tn
//              :apertium.org,ap // I think its apertium.org
//              :reto-vartaro,rv 
//                      each root word has an xml file,  but how to you find this xml file?
//                      there is a xml link on the bottom of a search result,  but I can't figure 
//                      out a way to get to this info.
//              :project gutenburg, pg
//              :google books, gb
//  BUT NEXT UP ЄЭ smart.fm  
// it also assumes epo-eng

function getphp_AlexVortaro ($vorto)
    {
        $AVurl1 = "http://vortaro.us.to/ajax/epo/eng/"; 
        $AVurl2 = "/?callback=";
        $AVfinalurl= $AVurl1 . $vorto . $AVurl2;


        $AVcontent = file_get_contents($AVfinalurl) ;

        // Now we need to trim the () jsonp to json
        $AVcontent = substr($AVcontent, 1);
        $AVcontent = substr($AVcontent,0,-1);

        $AVDecode = json_decode($AVcontent);

        return ($AVDecode);
    }


function getphp_Smartfm($vorto)
    {
        $SFurl="http://api.smart.fm/items/matching/";
        // $SFurl2=urlencode($vorto); // +".json";
        $SFurl3="?language=eo&translation_language=en";
        $SFfinalurl = $SFurl . $vorto . ".json" . $SFurl3;  // you can change .json to .xml

        $SFcontent = file_get_contents($SFfinalurl);
        $SFDecode = json_decode($SFcontent);

        return ($SFDecode);
    }


$AVvorto = getphp_AlexVortaro ($vorto);
$SFvorto = getphp_Smartfm($vorto);



function showphp_AlexVortaro ($AVvorto)
    {
    $AVvortoshow = $AVvorto->text;
    echo $AVvortoshow;

    }

showphp_AlexVortaro ($AVvorto);



function showphp_Smartfm($SFvorto)
{
   // $objects is the array with all those objects
foreach($SFvorto as $object)
{
  echo $object->cue->language; // language

  foreach($object->responses as $response)
  {
    // if there are no quizzes, we skip the part below
    // we skip it because $object->quizzes will produce a warning or a notice
    // if "quizess" is not a member of the $object
    if(!isset($object->quizzes))
    {
      continue;
    }

    // quizess
    foreach($response->quizzes as $quiz)
    {
      echo $quiz->question; // question
      echo $quiz->answer; // answer
    }
  }
}


}

showphp_Smartfm($SFvorto);

?>

</body>
</html>
A: 

Enable all the error reportings:

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//or directly edit your php.ini !

and try with:

foreach($response->quizzes as $quiz)
    {
      var_dump($quiz->question); // question
      var_dump($quiz->answer); // answer
    }

and see what is going on

DaNieL
foreach($response->quizzes as $quiz) { var_dump($quiz->question); // question var_dump($quiz->answer); // answer }Nothing and foreach($response->quizzes as $quiz) { echo var_dump($quiz->question); // question echo var_dump($quiz->answer); // answer }nothingI believe I have error reporting on? how do i make sure?
Klanestro
Nothing at all for the above, how do I make sure i have error reporting on?
Klanestro
Updqated my answer.
DaNieL
still nothing ★✩ there is info in the json file regarding someone elses comment
Klanestro
A: 

Start doing 'echo-debugging'.

print_r($response); 
print_r($response->quizzes);

foreach($response->quizzes as $quiz)
    {
      echo $quiz->question; // question
      echo $quiz->answer; // answer
    }
  1. Maybe there are no $response->quizzes
  2. Maybe the question and answer are empty string
  3. Maybe this code is never being reached
  4. Maybe it's outputting inside an HTML tag and you never thought to check View Source
  5. Maybe it's dying way earlier in the script and you don't have error reporting turned on.
Tom Ritter
1-2.There is information in $response->quizzes in the json file; see http://stackoverflow.com/questions/2116963/navigating-objects-and-arrays 3. The code is going all the way through I know because it echo's at the very end, 4. I live in view source5 don't think so, I see my errors I did turn it on when I installed it.
Klanestro
+1  A: 

This fixed it

-    if(!isset($object->quizzes))
0
+    if(!isset($object->responses))

Go here http://github.com/klanestro/Vortoj/commit/625fce9ffbd2a4d45d7b8dffddff6986fe521a00#comment_43364

Klanestro