Echo Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rimple Saini
    New Member
    • Aug 2010
    • 3

    Echo Problem

    Code:
     // xml.php file
    <?php 
    error_reporting(E_ALL ^ E_NOTICE);
    ob_start();
    session_start();
    //include("connect.php");
    
    $mysql_link = mysql_connect("localhost", "root", "");
    mysql_select_db("test",$mysql_link);
    mysql_query('SET character_set_results=utf8');
    
    
    ?>
    <?php
    
    header('Content-Type: text/html; charset=utf-8');
    
      $sql="select * from hindinn order by id;";
     $cmd=mysql_query($sql);
     while ($rs = mysql_fetch_array($cmd)){
      echo '<pre>';
      print_r($rs);            // here it echoes successfully
     }
      
     ?>
     <?php
    $xml = "<?xml version='1.0' encoding='utf-8'?>
        <languages>
           <languages>".test.print_r($rs)."</languages> //// here it DOESNOT echoes, echo test1
       </languages>";
    echo $xml; 
    
     ?>
    can u just tell me why, i shall be thankful to you.
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    What is test.print_r($r s)?

    Why not just print_r($rs) like in your previous echo?

    Comment

    • Rimple Saini
      New Member
      • Aug 2010
      • 3

      #3
      Respected sir/mam
      can u just help to print print_r($rs) only, leave "test" to echo

      <languages>".te st.print_r($rs) ."</languages> //it echo test1


      <languages>".pr int_r($rs)."</languages> //it echo 1

      while print_r($rs) array contains 7 records in my table

      Comment

      • perhapscwk
        New Member
        • Sep 2007
        • 123

        #4
        use below instead

        Code:
         <?php 
        $xml = "<?xml version='1.0' encoding='utf-8'?> 
            <languages> 
               <languages>test".print_r($rs)."</languages> 
           </languages>"; 
        echo $xml;  
          
         ?>

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by Rimple Saini
          Respected sir/mam
          can u just help to print print_r($rs) only, leave "test" to echo

          <languages>".te st.print_r($rs) ."</languages> //it echo test1


          <languages>".pr int_r($rs)."</languages> //it echo 1

          while print_r($rs) array contains 7 records in my table
          You realize that your first print_r call, on line #22, is inside a loop which loops through the database results. However the one on line #29 is not.

          That's why your first print_r prints all seven while the second one print's only one.

          Comment

          Working...