$sql="select * from xsktdl where text1 like '%$gjc%' union all select * from xsktdl2 where text1 like '%$gjc%'";
$sql="select * from (select * from xsktdl union all select * from xsktdl2) where text1 like '%$gjc%'";
2种方式都不行  查询结果是无记录

解决方案 »

  1.   

    那应该怎么写才对
    $sql="select * from xsktdl where text1 like '%$gjc%'";  
    这是1个表的写法   怎么写上2个表的
      

  2.   

    xuzuning   你会不会啊    给写出来摆
      

  3.   

    union 要求联合的结果集对应列类性一致
      

  4.   

    我的2个表的列名都有text1
      

  5.   

    这是全部的代码<?php 
    $title=htmlspecialchars($_POST["gjc"]);
    $resultt=mysql_query("select * from xsktdl where text1 like '%$title%' union all select * from xsktdl2 where text1 like '%$title%'");
    $i=9; 
    $j=0;
    while($rowww=mysql_fetch_array($resultt)) 

    $j++; 
    ?> <?=$rowww["text1"]?><br><?php 
    if($j==$i) 

    $j=0; 
    echo "</tr>"; 
    echo "<tr>"; 


    for($k=$i-$j;$k>0;$k--) 

    echo "<td></td>"; 

    ?> 
      

  6.   

    xuzuning   你会不会啊    会就直接给写出来摆
      

  7.   

    多表查询是这样的
    select * from table_a, table_b where 1 and table_a.field1 = table_b.filed1
    形式是这样,希望能理解
      

  8.   

    这样试试$sql = "select text1 from xsktdl where text1 like '%$gjc%' union all select text1 from xsktdl2 where text1 like '%$gjc%'";
    如果这样可以,说明xsktdl与xsktd2的字段数不同。
    所以你需要在select时选择共同的字段,否则会出错。