Guest User

Untitled

a guest
Aug 25th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 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 IN RESULTS!
  25.  
  26. }
  27. } else {
  28. echo "0 results";
  29. }
  30. $conn->close();
  31. ?>
Add Comment
Please, Sign In to add comment