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

时间:2016-04-25 02:37:57

标签: javascript php html dom innerhtml

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>

1 个答案:

答案 0 :(得分:2)

为什么不这样做?

&#13;
&#13;
  <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>
&#13;
&#13;
&#13;