-1

I have a table with data in it ID, Name, Task, Business. I am trying to show all records based on the Business category.

I would like a separate page to show all the businesses and then when you click on the name it displays all the records associated with it.

I am unsure of how to display this.

I can almost see what I want in SQL workbench but I am unsure how to do this is php code..

SELECT * FROM job2 where business="MR Plumber"

I want the "Mr plumber" to be what ever business I click on the business page.

I would like to have a page to list the businesses and then when I click on the business name link and displays all records associated to it.

iminiki
  • 2,549
  • 12
  • 35
  • 45
  • See https://meta.stackoverflow.com/questions/333952/why-should-i-provide-a-minimal-reproducible-example-for-a-very-simple-sql-query – Strawberry Oct 12 '19 at 09:35

1 Answers1

-1

Try this.

<?php $servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  echo "error";
} 

$sql = "your sql";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["column_name"];
    }
} else {
    echo "0 results";
}
$conn->close();
?>
Mahesh
  • 371
  • 3
  • 11
  • I am unsure how to display all records based on a business name. – Icelander1 Oct 12 '19 at 09:27
  • [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) It is a very bad idea to use `die(mysqli_error($conn));` in your code, because it could potentially leak sensitive information. See this post for more explanation: [mysqli or die, does it have to die?](https://stackoverflow.com/a/15320411/1839439) – Dharman Oct 12 '19 at 09:44