sách gpt4 ăn đã đi

php - mysql, ASC 现有mysql查询的数据

In lại Tác giả: Walker 123 更新时间:2023-11-30 22:55:28 26 4
mua khóa gpt4 giày nike

如果我有此查询,我需要有关此数据的帮助

SELECT count(*),username
FROM products
Ở ĐÂU
description LIKE '%Yes%'
hoặc
description LIKE '%yes%'
GROUP BY username

我需要对这些数据进行升序排列,这样我的数据才会显示为这个

username | description
a | 3
b | 1

这是我的 PHP 代码,我想在我的 Android 应用程序上显示它。

 $result = mysql_query("

SELECT count(*),username
FROM products
Ở ĐÂU
description LIKE '%Yes%'
hoặc
description LIKE '%yes%'
GROUP BY username

" ) or die(mysql_error());



// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();

while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["username"] = $row["username"];
$product["description"] = $row["count(*)"];

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

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

// echoing JSON response
echo json_encode($response);
} khác {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";

// echo no users JSON
echo json_encode($response);
}

非常感谢您的帮助!!

câu trả lời hay nhất

如果可行,试试这个

  $sql = "SELECT username,count(*) as description
FROM products
Ở ĐÂU
description LIKE '%Yes%'
hoặc
description LIKE '%yes%'
GROUP BY username
ORDER BY description ASC";

$q = mysql_query($sql);
echo mysql_num_rows($q);
$output = "";
$output .= "";
$output .= "";
$output .= "";
while($row = mysql_fetch_assoc($q)){
$output .= "";
$output .= "";
$output .= "";

$output .="";
}

$output .="
";
$output .= "Description";
$output .= "
";
$output .= "Username";
$output .= "
";
$output .= $row["description"];
$output .= "
";
$output .= $row["username"];
$output .= "
";
echo $output;

如果你想让它在 json 中,最后将它发送到 android

  $sql = "SELECT username,count(*) as description
FROM products
Ở ĐÂU
description LIKE '%Yes%'
hoặc
description LIKE '%yes%'
GROUP BY username
ORDER BY description ASC";

$q = mysql_query($sql);
$q = mysql_query($sql);
$product = array();
while ($row = mysql_fetch_array($q))
{


$product[]["username"] = $row["username"];
$product[]["description"] = $row["description"];
}
echo json_encode($product);

这会给你这样的输出

 [{"username":"a"},{"description":"3"},{"username":""},{"description":"1"}] 

如果您想根据用户名而不是描述进行排序,请将查询更改为

 $sql = "SELECT username,count(*) as description
FROM products
Ở ĐÂU
description LIKE '%Yes%'
hoặc
description LIKE '%yes%'
GROUP BY username
ORDER BY username ASC";

关于php - mysql, ASC 现有mysql查询的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26575711/

26 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress