PHP- 在 table 的每一行中动态插入带有 javascript 的 innerhtml

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

InnerHtml 在这种情况下不起作用,我想做这样的事情:

  <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>

你为什么不这样做呢?

  <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>