【问题标题】:Display Result from two tables sql using php使用php从两个表sql显示结果
【发布时间】:2018-09-26 20:52:56
【问题描述】:

我有 2 个表,分别称为 postpcgames

if $_GET['game']; is =action

它将从列类别中搜索对表帖和 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 }; ?> 

【问题讨论】:

  • 问题/问题是什么?
  • 看到&lt;a href="./post_list.html"&gt;&lt;?php echo $row['title']; ?&gt; 是否指示您的服务器将.html 文件视为php?你有没有安装 webserver/php?
  • 我不会等一夜的。我们不在同一个时区你和我。除非我们是,而且它接近午夜;所以我也在我的路上。你可以熬夜,我不行。祝你好运。
  • 对不起,我没有编辑链接,我只是想得到 来自表 pcgames 和具有数据“动作”的帖子。
  • 你需要告诉问题是什么,其次$conDB的值是什么,如果你只是通过添加die或mysqli_error进行错误测试,则打开或错误报告并使用错误消息跨度>

标签: php mysql display


【解决方案1】:

我认为您的意思是从表格帖子和具有类别条件的 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 2020-06-02
    • 2011-08-16
    • 1970-01-01
    相关资源
    最近更新 更多