title: using json_encode and echo in one php page
body: <p>I'm using the below code to return values to the javascript file, I want just to return the json_encode value, while the echo value I want tp printed on the page without return it to javascript .. how could I do that?</p>
  <p>Like the below code will return 1 or 2 and it will return the value that is inside the while loop while I just want to return the values that are inside the json_encode ..</p>
  <pre><code>&lt;?php
  
      session_start();
      include &quot;connect.php&quot;;
      $access = isset($_SESSION[&quot;userid&quot;]);
      if ($access) {
          
          $nameID = filter_input(INPUT_GET, &quot;nameID&quot;, FILTER_VALIDATE_INT);
  
          if($nameID !== null &amp;&amp; $nameID !== false){
              $SQL = $dbh-&gt;prepare(&quot;SELECT * FROM cart where nameID = ?&quot;);
              if ($SQL-&gt;execute([$nameID])){
                  if ($SQL-&gt;rowCount() &gt; 0){
                      echo json_encode(1);
                  }else{
                      $SQLI = $dbh-&gt;prepare(&quot;INSERT INTO cart VALUES (?,?,?)&quot;);
                      if ($SQLI-&gt;execute([$_SESSION[&quot;userid&quot;], $nameID, 1])) {
                          if ($SQLI-&gt;rowCount() &gt; 0) {
                              echo json_encode(2);
                          }
                      }
                  }
              }   
          }
          
          show the name list ..
          $SQLS = $dbh-&gt;prepare(&quot;SELECT * from users where userid = ?&quot;); 
          
          if ($SQLS-&gt;execute([$_SESSION[&quot;userid&quot;]])){
              if ($SQLS-&gt;rowCount() &gt; 0){
                  while ($row = $SQLS-&gt;fetch()) {
                      echo &quot;&lt;br&gt;&quot; . $row ['userName'] . &quot;&lt;br&gt;&quot;;           
                  }
              }
          }
      }
  </code></pre>