PHP 执行后的结果再重新排序的问题 - V2EX
brando
V2EX    PHP

PHP 执行后的结果再重新排序的问题

  •  
  •   brando May 12, 2015 3074 views
    This topic created in 4020 days ago, the information mentioned may be changed or developed.
    table1
    +----+----------+
    | id | name |
    | 1 | a |
    | 2 | b |
    | 3 | c |
    | 4 | d |
    +----+----------+


    table2
    +----+----------+
    | id | tid |
    | 1 | 3 |
    | 2 | 1 |
    | 3 | 4 |
    | 4 | 2 |
    +----+----------+

    输出的结果:
    | table2.id | table2.tid | table1.id | table1.name |
    | 2 | 1 | 1 | a |
    | 4 | 2 | 2 | b |
    | 1 | 3 | 3 | c |
    | 3 | 4 | 4 | d |

    用一个简单的PHP写了下,但排序完全是,糟糕来解释了

    $row=mysql_fetch_array($sql);
    $sql=mysql_query("select * from table1 where 1",$conn);
    while($row=mysql_fetch_array($sql)){
    ?>

    <?php
    $ordertime2 = date("Y-m");
    $sql2 = mysql_query("select * from table2 where tid='".$row[id]."' and ordertime like '".$ordertime2."%' ",$conn);
    while($row2=mysql_fetch_array($sql2)){
    ?>

    <tr>
    <td align="center"><?php echo $row[name];?></td>
    <td align="center"><?php echo $row2[tid];?></td>
    <td align="center">whatever</td>
    </tr>


    小弟学艺不精,现在想 以table2.tid的序号进行排序,还请过路大侠们指点,谢谢~
    4 replies    2015-05-12 10:44:21 +08:00
    l12ab
        1
    l12ab  
       May 12, 2015   1
    ordertime 字段哪里来的?

    select * from table2 t2, table1 t1 WHERE t2.tid = t1.id order by t2.id asc
    b821025551b
        3
    b821025551b  
       May 12, 2015   1
    order by t2.id asc(desc)
    brando
        4
    brando  
    OP
       May 12, 2015
    ordertime 字段可以无视,不是重点。
    鉴于一些表的特殊性,还是要使用'tid='".$row[id]."' 来处理。
    About     Help     Advertise     Blog     API     FAQ     Solana     3118 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 43ms UTC 00:02 PVG 08:02 LAX 17:02 JFK 20:02
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86