douyou2234 2011-11-14 15:09
浏览 6
已采纳

使用MySql查询和PHP的不同结果[关闭]

$sql=Select A.a,B.b,b,C.c

from A,B,C 
group by 
A.a, B.b,C.c
order by A.oder_nr,A.a

$row_Sql= mysql_query($sql,$db) or die (mysql_error());
$record_set=  mysql_fetch_assoc($row_Sql);
$totalRows_$row_sql=mysql_num_rows($row_Sql);
$A=''
$B=''
while ( $record_set = mysql_fetch_assoc($row_Sql) ) 
{
   if ( $A != $record_set[ 'A' ] ) 
   {

       $A = $record_set[ 'A' ];

       echo "<h2>$A</h2>";

   }
   if ( $B!= $record_set[ 'b' ] ) 
   {

       $B = $record_set[ 'b' ];

       echo "<h3>$B</h3>";


   }
   echo "<li><a href=\"Detail.php?A_id=".$record_set['A_id']. "\">";
   echo $record_set['c'];
  echo $record_set['d']; ?></br></a></li>

   <?php } ?>

Using Sql query alone returns the complete result but using it with the php code always removes the first result.the query returns for example 1,2,3,4 but the php starts from 2,3,4. Any idea?

  • 写回答

1条回答 默认 最新

  • douguan8940 2011-11-14 15:10
    关注

    You're calling $record_set= mysql_fetch_assoc($row_Sql); once above the loop. This will effectively trim the first row off the resultset.

    You also appear to be using variable variables, not sure if that's intentional or a typo:

    while ( $record_set = mysql_fetch_assoc($$row_Sql) ) 
    //                                      ^---------- variable variables!
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统