我有我的數據庫三種不同的表,我需要從所有表中搜索內容,但沒有工作,因爲它有不同的屬性PHP代碼從多個表中搜索在DATABSE
這裏是我的表結構
表1名>>博文
| bid | title | body | author |
|----- |------- |------------- |-------- |
| 1 | new | hello new | you |
| 2 | cast | broadcast | me |
| 3 | hack | who hack us | you |
表2名>> forumnew
| fid | ftitle | fbody | user |
|----- |------- |------------- |-------- |
| 1 | new forum | hello new | you |
| 2 | cast me | broadcast | me |
| 3 | hack you | who hack him | us |
表3名>>下載
| did | file | disc | type |
|----- |------- |------------- |-------- |
| 1 | whoweare | hello new | php |
| 2 | cast | broadcast | html |
| 3 | hack | who hack us | c++ |
我用這個PHP代碼從單個表中選擇
<?php
if(isset($_GET['postid'])){
$search = $_GET['postid'];
$output;
if(!empty($search)){
$dsn = new DBController();
$dsn->prepare("SELECT * FROM blogpost WHERE title LIKE :search LIMIT 10");
$dsn->bind(':search', '%'.$search.'%');
$dsn->execute();
$output = $dsn->getAll();
$dsn->free();
}
if(!is_null($output)):
$html = '';
foreach($output as $i => $row){
$id = $row->bid;
$title = $row->title;
$cont = $row->body;
$html .= '<article> <div class="spacer js-gps-track">
<a href="'.$id.'" class="readmore related ret">'.$title.'</a>
$body
</div></article>';
}
echo $html;
else: ?>
<h5 style="color: #2f2f2f;">No related search found</h5><br/>
<?php endif;
}?>
編輯您的文章,以顯示哪些字段與其他表匹配,並添加搜索條件示例顯示預期結果 – dbmitch
好@dbmitch我試圖讓表,但沒有工作 – Frank
@dbmitch,我的表結構看起來如何 – Frank