how to insert echo into the specific html element like div which has an id or class

  1. <?php  
  2. <html
  3. <head
  4. <style type="text/css"
  5. body{background:#666666;} 
  6. div{border:1px solid red;} 
  7. </style
  8. </head
  9. <body
  10. <?php 
  11.  
  12. $con mysql_connect("localhost","root",""); 
  13. if (!$con
  14. die('Could not connect: ' mysql_error()); 
  15.  
  16. mysql_select_db("juliver"$con); 
  17.  
  18. $result mysql_query("SELECT * FROM hi"); 
  19.  
  20. while($row mysql_fetch_array($result)) 
  21.  
  22. echo '<img src="'.$row['name'].'" />';   
  23. echo "<div>".$row['name']."</div>"
  24. echo "<div>".$row['title']."</div>"
  25. echo "<div>".$row['description']."</div>"
  26. echo "<div>".$row['link']."</div>"
  27. echo " "
  28.  
  29. mysql_close($con); 
  30.  
  31. ?> 
  32. </body> 
  33. </html> 
  34.  



    the above code works.

    now, I want to insert this
    1. <?php  
    2. echo '<img src="'.$row['name'].'" />';  
    3. echo "<div>".$row['name']."</div>"
    4. echo "<div>".$row['title']."</div>"
    5. echo "<div>".$row['description']."</div>"
    6. echo "<div>".$row['link']."</div>"
    7. echo " "
    8. into the specified div or other element in the htmlexamplei will insert this 
    9.  
    10. echo '<img src="'.$row['name'].'" />'
    11.  

      into the html element .
      PHP JAVASCRIPT JQUERY

      Submitted by hakam On Saturday, 17 August 2013.
      Category: PHP

      [RESOLVED]

      1
      1 Answers.
       
      Super User
      crooker

      Re:how to insert echo into the specific html element like div which has an id or class

      make the result in string variable as bellow then echo it anywhere u needed.

      1. <?php  
      2.  
      3. $result ''
      4.  
      5. while($row mysql_fetch_array($result))  
      6. {  
      7.   
      8. $result .=  '<img src="'.$row['name'].'" />';    
      9. $result .= "<div>".$row['name']."</div>";  
      10. $result .= "<div>".$row['title']."</div>";  
      11. $result .= "<div>".$row['description']."</div>";  
      12. $result .= "<div>".$row['link']."</div>";  
      13. $result .=  " ";  
      14. }  
      15.  
      16.  
      17. ?> 
      18.  
      19. <div id="mydiv"><?php echo $result?></div> 
      20.  
        Submitted by Super User On Tuesday, 20 August 2013
        0
        This Answer has been Chosen as Best Answer
        Question is marked as resolved.