![](/img/trans.png)
[英]How to SELECT all the tables mySql of a db and show query order by data, tables have the same structure
[英]Select query from more tables, which have the same structure
當列具有某種結構時,我如何從更多表中選擇查詢。 所以我想使用變量從 travel 和 istorie 表中選擇 id、poza 等
$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);
我還想整合來自表 travel的查詢,不僅來自表istorie ,兩者都有一些結構id, titlu, link, poza, alt, Keywords
如果兩個表之間的列數和類型匹配,則可以使用 union 或 union all
Union 只選擇兩個表之間的字典行,Union ALL 選擇所有行
$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
" ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.