小编mpr*_*rog的帖子

如何在php mysql中获取结果的所有行?

在我的表中我有2条记录companyid = 1,但是当我运行下面的php时,companyid = 1它只返回第一个!
我怎样才能获取所有记录?

php文件:

if (isset($_GET["companyid"])) {
$companyid = $_GET['companyid'];

// get a product from products table
$result = mysql_query("SELECT * FROM `products`         
                        WHERE companyid = $companyid;");

if (!empty($result)) {      

    if (mysql_num_rows($result) > 0) {

   while($row = mysql_fetch_assoc($result)){
      $product = array();
      $product["pid"] = $row["pid"];
      $product["productname"] = $row["productname"];        
    }

   $response["product"] = array();

       array_push($response["product"], $product);

        // success
       $response["success"] = 1;

   echo json_encode($response);

    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No …
Run Code Online (Sandbox Code Playgroud)

php mysql json

4
推荐指数
3
解决办法
7万
查看次数

标签 统计

json ×1

mysql ×1

php ×1