2016-10-17 71 views
-1

當列具有某些結構時,我如何從更多表中選擇查詢。所以我想用選擇ID,波薩等,從旅遊和istorie表變量從更多表中選擇具有相同結構的查詢

$sql = "SELECT id, titlu, link, poza, alt, keywords FROM istorie WHERE approved='1' LIKE '%''".$keyword."''%'='%''".$keyword."''%' ORDER BY RAND() LIMIT 3" ; 
$query = mysqli_query($con, $sql); 
if(!$query){ 
    printf("Error: %s\n", mysqli_error($con)); 
    exit();} 
$istorielist = ''; 
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ 
    $id = $row["id"]; 
    $titlu = $row["titlu"]; 
    $link = $row["link"]; 
    $poza = $row["poza"]; 
    $alt = $row["alt"]; 
    $istorielist .= '<div id="articol-content-more"><a href="/istorie/'.$link.'"><img src="/images/'.$poza.'.jpg"class="articol-content-more-image" alt="'.$alt.'"><p class="articol-content-more-title">'.$titlu.'</p></a><span><a class="articol-content-more-afla" href="/istorie/'.$link.'">Citește mai multe</a></span><span class="articol-content-more-fl"><div class="fb-share-button" data-layout="button_count" data-href="http://esticurios.ro/istorie/'.$link.'"></div></span></div>'; 
} 
mysqli_free_result($query); 

我想還集成了來自工作臺行程查詢,不僅從表istorie ,兩者具有某種結構ID,titlu,鏈接,波薩,ALT,關鍵詞

+0

在你的查詢中使用union all。從t1選擇ID union從t2選擇ID –

+0

你能給我一個例如的PHP代碼?我不知道 –

+0

在這裏你有一些例子https://www.techonthenet.com/mysql/union_all.php –

回答

0

如果號碼和兩個表中可以使用工會或工會所有
聯盟選擇的列匹配的類型只有在兩個表格之間的聯合行,聯合全部選擇所有行

$sql = "SELECT id, titlu, link, poza, alt, keywords 
      FROM istorie 
      WHERE approved='1' LIKE '%''".$keyword."''%'='%''".$keyword."''%' ORDER BY RAND() LIMIT 3 
      UNION ALL 
     SELECT id, titlu, link, poza, alt, keywords 
      FROM travel 
      WHERE approved='1' LIKE '%''".$keyword."''%'='%''".$keyword."''%' ORDER BY RAND() LIMIT 3    
      " ; 
相關問題