Thursday, 15 September 2011

php - mysql, ASC the data of the existing mysql query -



php - mysql, ASC the data of the existing mysql query -

i need help on info if have query

select count(*),username products description '%yes%' or description '%yes%' grouping username

i need asc info appear info this

username | description | 3 b | 1

and php code want show , display on android apps.

$result = mysql_query(" select count(*),username products description '%yes%' or description '%yes%' grouping username " ) or die(mysql_error()); // check empty result if (mysql_num_rows($result) > 0) { // looping through 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); } else { // no products found $response["success"] = 0; $response["message"] = "no products found"; // echo no users json echo json_encode($response); }

your help much appreciated!!

try if works

$sql = "select username,count(*) description products description '%yes%' or description '%yes%' grouping username order description asc"; $q = mysql_query($sql); echo mysql_num_rows($q); $output = "<table>"; $output .= "<td>"; $output .= "description"; $output .= "</td>"; $output .= "<td>"; $output .= "username"; $output .= "</td>"; $output .= "</tr>"; while($row = mysql_fetch_assoc($q)){ $output .= "<tr>"; $output .= "<td>"; $output .= $row["description"]; $output .= "</td>"; $output .= "<td>"; $output .= $row["username"]; $output .= "</td>"; $output .="</tr>"; } $output .="</table>"; echo $output;

if want in json send android

$sql = "select username,count(*) description products description '%yes%' or description '%yes%' grouping username order 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);

this give output this

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

if want sort respect username instead of descripton, alter query to

$sql = "select username,count(*) description products description '%yes%' or description '%yes%' grouping username order username asc";

php android mysql

No comments:

Post a Comment