Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从MySQL表中检索相同类别的数据以显示在网页上_Php_Html_Mysql - Fatal编程技术网

Php 从MySQL表中检索相同类别的数据以显示在网页上

Php 从MySQL表中检索相同类别的数据以显示在网页上,php,html,mysql,Php,Html,Mysql,你好,我已经跟随你很久了 我有一个非常严重的问题 我在mysql数据库中有一个表 餐桌生意 ID. BNAME. CATEGORY description 1. Stamp. Computer Deals with hardware repair 2. Yastlabc. Computer Software and hardware 3. Eastern. Consultant General business

你好,我已经跟随你很久了 我有一个非常严重的问题 我在mysql数据库中有一个表 餐桌生意

ID. BNAME.  CATEGORY            description
1. Stamp.       Computer        Deals with hardware repair
2. Yastlabc.    Computer       Software and hardware
3. Eastern.        Consultant   General business consulting
4. Goggreen.    Medical         all medical and testing
链接到A页中的

<a href="category.php?id=<?php echo['category'];> "> <?php echo row['category']; ?> </a>

你应该循环抛出你的结果集

<?php
require 'dbconfig/dbcon.php';
if(isset($_GET['id'])){
    $id = $_GET['id'];
    $sql = "select * from business where id=".$id;
         $result = mysqli_query($conn, $sql);
     if(mysqli_num_rows($result)>0){
         echo "Results to Display";
         while ($row = mysqli_fetch_assoc($result)) {
           echo "<h4>".$row['bname']."</h4>";
           echo "<p>".$row['description']."</p>";
       }
    }else{
        $errorMsg= 'Could not select record';
    }
}

?>
表格业务

然后查询应该类似于
“select*from business”,其中category_id=“.id.$id
,其余代码相同


祝你好运。

我认为$row是一个数组,你可以使用循环打印所有数据。
mysqli\u fetch\u assoc
只从结果集中提取一条记录,你需要在循环中这样做,或者使用
mysqli\u fetch\u all
一次性提取所有记录。但是,如果您从该表中选择“按ID”,那么您将只获得一条记录作为开始。如果要选择category=computer的所有项目,则需要在WHERE子句中使用它。您不能通过id按类别进行选择,因为此处没有任何类别id。(您可能应该进行适当的规范化。)
stamp
Deals with hardware repair

------------------------------------------
Yastlabc
 Software and hardware

-----------------------------------------------
<?php
require 'dbconfig/dbcon.php';
if(isset($_GET['id'])){
    $id = $_GET['id'];
    $sql = "select * from business where id=".$id;
         $result = mysqli_query($conn, $sql);
     if(mysqli_num_rows($result)>0){
         echo "Results to Display";
         while ($row = mysqli_fetch_assoc($result)) {
           echo "<h4>".$row['bname']."</h4>";
           echo "<p>".$row['description']."</p>";
       }
    }else{
        $errorMsg= 'Could not select record';
    }
}

?>

Results to Display
<h4>

<?php echo $row['bname'];?>
</h4>
<p>

<?php echo $row['description'];?>
</p>
ID    NAME
1     Computer
2     Consultant
3     Medical

ID. BNAME.  CATEGORY_ID    Description
1. Stamp.       1          Deals with hardware repair
2. Yastlabc.    1          Software and hardware
3. Eastern.     2          General business consulting
4. Goggreen.    3          all medical and testing