我在showphoto.php页取得图片id,想把它传给show.php页显示大图,然后又传给图片评论那一页comment.php,把每个评论内容和图片的id对应起来,我在下面这样写不对,要怎么修改??求帮忙
$query=mysql_query("select * from tb_tpsc where type='达人收藏' order by id desc limit  ".($page_num-1)*$row_per_page." ,$row_per_page",$conn);
while($row=mysql_fetch_array($query)) 
     {
            <a href=commentadd.php?id=".$row[id]."></a>;
echo "<a href=show.php?id=".$row[id]."><img widht=100 height=100  src='$row[tpmc]'></a>"; 
      }                                 
   

解决方案 »

  1.   


    while($row=mysql_fetch_array($query)) 
      {
    echo  "<a href=commentadd.php?id=$row[id]></a>";//ID已经GET形式传递,评论页可以$_GET['id']获取到图片ID
    echo "<a href=show.php?id=".$row[id]."><img widht=100 height=100 src='$row[tpmc]'></a>"; //同上
      }   
      

  2.   

    我照着做了,comment.php页获取信息的代码是
    if($_POST["submit"]=="提交"){
            $tpid=$_GET[id];
    $content=$_POST[txt_content];
    $datetime=date("Y-m-d H:i:s");
    $INS="Insert Into tb_comment (tpid,content,datetime) Values ('$tpid','$content','$datetime')";
    $info=mysql_query($INS);
    图片的id没传过去,数据库里没有
      

  3.   

    这是URL传参,你的判断条件则是判断的表单数据,把这个判断去掉。
      

  4.   

    我发表评论是用表单做的,表单中评论信息是根据这个提交按钮传到数据库的。好像id没有传过去,我试着输出id,但没有输出
      

  5.   

    你是在哪个脚本里做的表单?
    如果在comment.php内
    <a href=commentadd.php?id=$row[id]>aaa</a>//你要先点击这个链接才能传过去参数
    然后在表单内做个隐藏数据项,$_GET['id']获取就可以了
      

  6.   

    我现在把表单那一页comment.php的代码复制到显示大图那一页
    showphoto.php
    $query=mysql_query("select * from tb_tpsc where type='达人收藏' order by id desc limit  ".($page_num-1)*$row_per_page." ,$row_per_page",$conn);
    while($row=mysql_fetch_array($query)) 
      {
    //echo  "<a href=commentadd.php?id=".$row[id].">aaa</a>";//ID已经GET形式传递,评论页可以$_GET['id']获取到图片ID
    echo "<a href=show.php?id=".$row[id]."><img widht=100 height=100 src='$row[tpmc]'></a>"; //同上
      }                       
    show.php
    <body>
    <table width="376" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
        <div align="center">
    <?php if($_GET['id']){
       $id=$_GET['id'];
       //echo"$id";
       $query=mysql_query("select * from tb_tpsc where id='$id'",$conn);
       $row=mysql_fetch_array($query); 
       echo "<img src='$row[tpmc]'>";
       }
       ?></div></td>
      </tr>
      <tr>
        <td> </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table> <form name="myform" method="post" action="commentadd.php">
     <table width="560" border="1" align="center" cellpadding="3" cellspacing="1" bordercolor="#9CC739" bgcolor="#FFFFFF">
      <tr align="left" colspan="2" >
       <td width="390" height="25" colspan="3" valign="top" bgcolor="#EFF7DE"> <span class="right_head"><SPAN  style="FONT-SIZE: 9pt; COLOR: #cc0033"></SPAN></span><span class="tableBorder_LTR"> 发表评论</span> </td>
                          </tr>
      <td height="112" align="center" valign="top" >
    <input name="tpid" type="hidden" value="<?php echo "$_GET[id]";?>">[/color]             
    <table width="500"  border="1" cellpadding="1" cellspacing="0" bordercolor="#D6E7A5" bgcolor="#FFFFFF">
    <tr>
     <td align="center">我要评论</td>
     <td width="410"><textarea name="txt_content" cols="66" rows="8" id="txt_content" ></textarea></td>
        </tr>
    <tr align="center">
    <td colspan="2"><input type="submit" name="submit" value="提交" onClick="return check();">
        &nbsp;
     <input type="reset" name="submit2" value="重置"></td>
        </tr>
      </table>     </td>
                  </table>
      </form> 
       </body>commentadd.php
    <?php
    header ( "Content-type: text/html; charset=gb2312" ); //设置文件编码格式
    session_start();
    include "conn/conn.php";
    //echo "$_GET[id]";
    if($_POST["submit"]=="提交"){
            $tpid=$_GET[id]; $content=$_POST[txt_content];
    $datetime=date("Y-m-d H:i:s");

    $INS="Insert Into tb_comment (tpid,content,datetime) Values ('$tpid','$content','$datetime')";
    $info=mysql_query($INS);
    if($info){

    echo "<script> alert('成功发表评论!');</script>";
    echo "<script> window.location.href='$_SERVER[HTTP_REFERER]';</script>";
    }
    else{
    echo "<script> alert('评论发表操作失败!');</script>";
    echo "<script> history.go(-1);</script>";
    }
    }
    ?>
      

  7.   

    $query=mysql_query("select * from tb_tpsc where type='达人收藏' order by id desc limit ".($page_num-1)*$row_per_page." ,$row_per_page",$conn);
    while($row=mysql_fetch_array($query)) 
      {
      echo '<img src=commentadd.php?id=".$row[id]."/>';
    echo '<img src=show.php?id=".$row[id]."><img widht=100 height=100 src='$row[tpmc]'></a>'; 
      }