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)){
?>
$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)){
?>
<?php echo $row[name];?><?php echo $row2[tid];?>whatever小弟学艺不精,现在想 以table2.tid的序号进行排序,还请过路大侠们指点,谢谢~