title: Echo inside or outside the function? Call function from itself?
body: <h1> Translation module </h1>
  
  <h2> Introduction </h2>
  
  <p>My code is working so far, but I don't know if this is the proper way of implementing what I want. I have a small function to translate strings on my webpage. If I call it with a number it searches the id in one table and only displays it if it's intended for that page. If I call it with a string, it searches the string in another table and, if the string doesn't exist, the function prints the string passed replacing '_' with spaces with a warning.</p>
  
  <p>There are 2 things I'd like to know if are implemented correctly (as stated, they work but I'm not sure if they're a good idea). But first the code.</p>
  
  <h2> The code </h2>
  
  <pre><code>// Function to output language strings.
  function text($Id)
      {
      // Already defined and tested that are valid (sql injection avoided also)
      global $Lang;
      global $FullUrl;
  
      if (is_int($Id))    // If a number is being passed
          {
          $results = mysql_query("SELECT * FROM translations WHERE id='$Id' AND page='$FullUrl'") or die ('Could not query:' . mysql_error());
          $row = mysql_fetch_assoc($results);
          if (!empty($row[$Lang])) echo $row[$Lang];  // If there is some, echo it
          else error($FullUrl,$Lang); // Else, calls error function
          }
  
      else    // If a string is being passed
          {
          $results = mysql_query("SELECT * FROM htranslations WHERE keyword='$Id'") or die ('Could not query:' . mysql_error());
          $row = mysql_fetch_assoc($results);
          if (!empty($row[$Lang])) echo $row[$Lang];  // If it exists in the table, echo it
          else    // Else (it doesn't exist)
              {
              $NewId = str_replace("_", " ", $Id);    // Replace the "_" with " "
              echo "&lt;span style='color: red;' title='";   // Set a red color (warning)
              text(Wrong_sentence);   // Call this function and echo "This sentence could be wrong"
              echo "'&gt;".$NewId."&lt;/span&gt;"; // Echo the passed string with spaces
              error($FullUrl,$Lang,$Id);
              }
          }
      }
  </code></pre>
  
  <h2> 1. Is it better to echo inside or outside the function? </h2>
  
  <p>I've already read <a href="https://stackoverflow.com/questions/3602383/php-echo-function-return-value-vs-echo-inside-function">this</a> question and I don't intend to manipulate the strings furthermore. So, from that post, I'm guessing that the best idea is to do as I already did, echoing inside the function, but I'd like to know your opinion for this particular case as I'm still not sure. <strong>Would it be better to return the value and echo that value or echo it from the function? Why?</strong> My question is focused in performance and making the code friendly.</p>
  
  <h2> 2. Is dangerous to call this function from inside the function? </h2>
  
  <p>As you can see, in one of the last lines I wrote <code>text(Wrong_sentence);</code>. I know that you can call a function from another, but <strong>can you call a function FROM that same function?</strong> I'm worried about it entering an infinite loop of calling itself, for example, if the table keyword <code>Wrong_sentence</code> got deleted or modified. Also, I'm not aware of other security consequences that could be there.</p>
  
  <p><strong>Any other kind of feedback on the code would be happily welcome!!</strong></p>