这是我写的计算发帖数的代码
$query_5=("select count(*) as total from lt_send where lt_send_small_type='".$_GET[$myrow_1['lt_small_type_content']]."'");
$result=mysql_query($query_5);
    $message_count=mysql_result($result,0,"total");
<?php echo $message_count ;?>
为什么输出的数据不对呢
我要输出的是小类标题对应的帖子总数

解决方案 »

  1.   

    代码流程没啥问题你查一下$_GET[$myrow_1['lt_small_type_content']],或者整条SQL语句,看看是否是预期中的值
      

  2.   

    在我記憶中mysql_result不是那樣用的吧
    應該是$result = mysql_query($query_5);
    $row = mysql_fetch_row($result);
    $message_count = $row[0];
    //或者
    $sql = "select * from lt_send where lt_send_small_type='{$_GET[$myrow_1['lt_small_type_content']]}'";
    $result = mysql_query($sql);
    $message_count = mysql_num_rows($result);
      

  3.   

    $query_5=("select count(*) as total from lt_send where lt_send_small_type='".$_GET[$myrow_1['lt_small_type_content']]."'");
    $result=mysql_query($query_5);
      $message_count=mysql_result($result,0,"total");
    <?php echo $message_count ;?>在php标签中套php标签不会报错么?....................................
    去掉标签,直接echo $message_count ;
      

  4.   


    <?php echo $message_count ;?>这句是后面才输出的,没在同一个PHP标签里面,他可以输出但是数据不对
      

  5.   

    好像这句没起作用,我用echo $sql;输出select * from lt_send where lt_send_small_type='' 是空值么,他没读的出
      

  6.   

    get 是怎么写的额?为什么是这种形式:
    $_GET[$myrow_1['lt_small_type_content']]把你传递到这个页面的链接代码写出来
      

  7.   

    这是我论坛首页的代码
    想在首页显示发帖总数
    <?php
      session_start();
    include("conn/conn.php"); 
                    
    $query=mysql_query("select * from lt_big_type");
    while($myrow=mysql_fetch_array($query)){  
    $querys=mysql_query("select * from lt_small_type where lt_big_type_content='$myrow[lt_big_type_content]'");
     

    $query_1=mysql_query("select * from lt_send where lt_send_type='1' and lt_send_small_type='".$_GET[content_1]."'");
    $myrows=mysql_fetch_array($querys);
    $sql = "select * from lt_send where lt_send_small_type='{$_GET[lt_small_type_content]}'";
    echo $sql;
    $result = mysql_query($sql);
    $message_count = mysql_num_rows($result);
    $query_6="select count(*) as total from lt_send where lt_send_small_type='$_GET[content_1]' and lt_send_type_hotspot=1";
    $result1=mysql_query($query_6);
        $message_count1=mysql_result($result1,0,"total");

    ?>
                <table  width="960" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#AFC7FC" class="k">
                  <tr class="l">
                    <td height="30" valign="middle" background="images/OOOPIC_ainibushi23tian_20090623180a81b92c32f0c5_conew1.jpg" class="d"(id_a<?php echo $myrow['lt_big_type_id'];?>)" >&nbsp;&nbsp;&nbsp; &nbsp;<img src="images/old.gif" width="23" height="26" />&nbsp; <?php echo $myrow['lt_big_type_content'];?></a></td>
                  </tr>
                  <tr class="l">
                    <td (id_a<?php echo $myrow['lt_big_type_id'];?>)" ><?php 
    $query_1=mysql_query("select * from lt_small_type where lt_big_type_content='$myrow[lt_big_type_content]' ");
     
    while($myrow_1=mysql_fetch_array($query_1)){
    ?>
                  <tr class="l">
                    <td height="23" colspan="2" align="left" valign="middle"><table width="1024" border="0">
                        <tr>
                          <td>&nbsp;&nbsp;
                            <table width="1024" border="0">
                              <tr>
                                <td width="135"><a href="in.php?content=<?php echo $myrow['lt_big_type_content'];?>&&content_1=<?php echo $myrow_1['lt_small_type_content'];?>" target=""><img src="images/0042.gif" /></a></td>
                                <td width="281"><p><a href="in.php?content=<?php echo $myrow['lt_big_type_content'];?>&&content_1=<?php echo $myrow_1['lt_small_type_content'];?>" target="" class="k"><?php echo $myrow_1['lt_small_type_content'];?></a></p>
                                <p>创建时间:<?php echo $myrow_1['lt_small_type_date'];?></p></td>
                                <td width="594"><table width="596" border="0">
                                  <tr>
                                    <td width="300" align="center" valign="top">发帖数</td>

                                    <td width="286" align="center">热门帖数</td>
                                  </tr>
                                  <tr>
                                    <td height="42" align="center"><?php 
    echo $message_count;
    ?></td>
                                    <td align="center"><?php echo $message_count1;?></td>
                                  </tr>
                                </table></td>
                              </tr>
                              <tr>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                                <td>&nbsp;</td>
                              </tr>
                            </table></td>
                        </tr>
                        
                      </table>
                    </td>
                  </tr>
                  <?php }?> 
      

  8.   

    <a href="in.php?content=<?php echo $myrow['lt_big_type_content'];?>&&content_1=<?php echo $myrow_1['lt_small_type_content'];?>" 参数明明用的是content_1,怎么用$_GET[$myrow_1['lt_small_type_content']]呢??改为$_GET['content_1']
      

  9.   

    改为content_1也不对 好像他压根就没读出来,请你再帮我看一下呗
      

  10.   

    代码太乱了,既然是首页,为什么会有这么多get参数?那些是点击后进入首页执行的代码放到if(isset($_GET['参数'])){}这个代码框中去。这代码乱的,都看不懂你思路...
      

  11.   

    就我是要从数据库中循环的读出论坛大类标题,和论坛小类标题,现在想计算出小类表中每个小类发表的帖子总数,和热帖总数。现在输出的帖子总数是一样的并且输出的数字也不对。
    $sql = "select * from lt_send where lt_send_small_type='{$_GET[content_1}'";
    echo $sql;
    $result = mysql_query($sql); 
    $message_count = mysql_num_rows($result);
    我想着是$sql那句没写对,因为输出$sql时他输出的是select * from lt_send where lt_send_small_type='' 好像where后面没有输出内容。想问你一下要怎么写,谢谢了

      

  12.   

    $sql = "select * from lt_send where lt_send_small_type='".$_GET[content_1]."'";