Guest User

Untitled

a guest
Aug 25th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. $servername = "localhost";
  2. $username = "";
  3. $password = "";
  4. $dbname = "";
  5.  
  6. // Connection
  7. $conn = new mysqli($servername, $username, $password, $dbname);
  8. // Check connection
  9. if ($conn->connect_error) {
  10. die("Connection failed: " . $conn->connect_error);
  11. }
  12.  
  13. $sql = "SELECT DISTINCT company FROM ads ORDER BY company ASC";
  14.  
  15. $result = $conn->query($sql);
  16.  
  17. if ($result->num_rows > 0) {
  18. // output data of each row
  19. while($row = $result->fetch_assoc()) {
  20.  
  21. // Display the company name
  22. echo $row["company"];
  23.  
  24. // I WOULD LIKE TO ECHO OUT HERE THE TOTAL OF EACH COMPANY HAS (COUNT) IN RESULTS!
  25.  
  26. }
  27. } else {
  28. echo "0 results";
  29. }
  30. $conn->close();
  31. ?>
  32.  
  33. $query = "SELECT
  34.  
  35. count(company) as count
  36.  
  37. FROM ads
  38.  
  39. GROUP BY company
  40.  
  41. ORDER BY company ASC"
  42.  
  43. SELECT
  44. company,
  45. COUNT(company)
  46. FROM
  47. ads
  48. GROUP BY
  49. company
  50. ORDER BY
  51. company
Add Comment
Please, Sign In to add comment