Search code examples
javascriptphphtmldominnerhtml

PHP- insert innerhtml with javascript dynamically in each row of table


InnerHtml not working in this case, i want to do something like this:

  <table width="100%" border="0" id="table2">
    
    <?php
     include("connection.php");
  $sql=mysql_query("select* from b1");
  while($res=mysql_fetch_array($sql))
  {
	$img=$res["img"];
	$url=$res["url"];
	  ?>
    <tr>
      <td><script>document.body.innerHTML="<a href='"+<?php echo '$url' ; ?>.value+"'><img src='"+<?php echo '$img' ; ?>+"' / ></a>" ;</script></td>
    </tr>
    <?php
  }
  ?>
  </table>


Solution

  • Why don't you just do this?

      <table width="100%" border="0" id="table2">
        
        <?php
         include("connection.php");
      $sql=mysql_query("select* from b1");
      while($res=mysql_fetch_array($sql))
      {
    	$img=$res["img"];
    	$url=$res["url"];
    	  ?>
        <tr>
          <td><a href="<?php echo $url ; ?>"><img src="<?php echo $img; ?>" / ></a></td>
        </tr>
        <?php
      }
      ?>
      </table>