使用php显示来自两个sql表的结果
我有两个表,分别是使用php显示来自两个sql表的结果,php,mysql,display,Php,Mysql,Display,我有两个表,分别是post和pcgames if$_获得['game'];is=action它将从列类别中搜索桌面post和pcgames上的操作 post表格 id|category |game ------------------ 1 | action |cabal ------------------ 2 | strategy |blackdessert ------------------ 3 | RPG |MUlegend ------------------ 4 |
post
和pcgames
if$_获得['game'];is=action
它将从列类别中搜索桌面post和pcgames上的操作 post表格
id|category |game
------------------
1 | action |cabal
------------------
2 | strategy |blackdessert
------------------
3 | RPG |MUlegend
------------------
4 | action |ragnarok
------------------
id|category |game
-------------------
1 | action |solidsnake
-------------------
2 | action |finalfantasy
-------------------
3 | RPG |kingdomhearts
-----------------
4 | action |tekken
-------------------
pcgames表格
id|category |game
------------------
1 | action |cabal
------------------
2 | strategy |blackdessert
------------------
3 | RPG |MUlegend
------------------
4 | action |ragnarok
------------------
id|category |game
-------------------
1 | action |solidsnake
-------------------
2 | action |finalfantasy
-------------------
3 | RPG |kingdomhearts
-----------------
4 | action |tekken
-------------------
结果
no|category |game
------------------
1 | action |cabal
------------------
2 | action |solidsnake
-------------------
3 | action |finalfantasy
-------------------
4 | action |tekken
-------------------
PHP
<?php
$game = $_GET['game'];
$ids = mysqli_real_escape_string($conDB,$id);
$query = "SELECT * FROM `post` WHERE `game` ='" . $game . "'";
$result = mysqli_query($conDB,$query);
while($row = mysqli_fetch_array($result)) {
?>
<li> <a href="./post_list.html"><?php echo $row['title']; ?></a> </li>
<?php }; ?>
我想你的意思是从具有类别条件的table post和pcgames中获取数据。如果你想这样做。在您的php上尝试以下操作:
<?php
$game = $_GET['game'];
$ids = mysqli_real_escape_string($conDB,$id);
$no = 1;
//this will be get data from post table
$query = "SELECT * FROM `post` WHERE `category` ='" . $game . "'";
$result = mysqli_query($conDB,$query);
//this will be get data from pcgames table
$query1 = "SELECT * FROM `pcgames` WHERE `category` ='" . $game . "'";
$result1 = mysqli_query($conDB,$query1);
?>
<table border=1>
<tr>
<th>No</th> <th>Category</th> <th>Game</th>
</tr>
<?php
//fetch data from post table
while($user_data = mysqli_fetch_array($result)) {
echo "<td>".$no++."</td>";
echo "<td>".$user_data['category']."</td>";
echo "<td>".$user_data['game']."</td>";
}
//fetch data from pcgames table
while($user_data1 = mysqli_fetch_array($result1)) {
echo "<td>".$no++."</td>";
echo "<td>".$user_data1['category']."</td>";
echo "<td>".$user_data1['game']."</td>";
}
?>
</table>
问题是什么?您是否指示服务器将.html
文件视为php?你安装了webserver/php吗?我不会等一整晚的。我们不在同一个时区,你和我。除非我们在同一个时区,而且时间接近午夜;所以我在路上。你可以熬夜,我不行。祝你好运。很抱歉,我没有编辑链接,我只是想从pcgames and post表中获取一个数据“action”。你需要告诉问题出在哪里,然后打开$conDB
或错误报告的值是多少,如果你只是通过添加die或mysqli\u错误进行错误或测试,请使用错误消息