如果我有此查询,我需要有关此数据的帮助
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);
}
非常感谢您的帮助!!
如果可行,试试这个
$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 .= "Description"; $output .= " | ";
$output .= ""; $output .= "Username"; $output .= " | ";
$output .= "";
while($row = mysql_fetch_assoc($q)){
$output .= "";
$output .= ""; $output .= $row["description"]; $output .= " | ";
$output .= ""; $output .= $row["username"]; $output .= " | ";
$output .="
";
}
$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";
Tôi là một lập trình viên xuất sắc, rất giỏi!