0

The base construction is:

  1. ID
  2. NameAds
  3. Category
  4. Price
  5. EndPrice

And i put in that base next parms:

  1. 1
  2. Example Name
  3. Ford
  4. 350$
  5. 280$

How can all this information be displayed on the page but only data that are categorized as 'ford'? And in the next page display only data that are categorized as 'Citroen'?

Mile
  • 62
  • 11
  • 2
    You should have done a little research on SQL before posting this question. A simple WHERE clause would achieve what you are asking. At least I assume so. It is difficult to understand your question without any code samples. – Taylor Buchanan Mar 01 '15 at 04:44

1 Answers1

1

If you use PDO, you can make a simple query to the db:

$query = $pdo->prepare("SELECT * FROM table_name WHERE category = ?");
$query->bindValue(1, $category);
$query->execute();

return $query->fetch();

If you have never used PDO before, this might look confusing, but the actual query to the db (SELECT * FROM...) will work for whichever method you're using. But I recommend using PDO for all your stuff.

You can also use MySQLi to accomplish this. Here is an example.

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

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT * FROM yourtablename WHERE category = 'ford'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

// output data of each row
while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"] . " - Name Ads: " . $row["NameAds"] . " - Category: " .  $row["category"] . " - Price: " .  $row["price"] . "<br />";
}
} else {
    echo "0 results";

}
$conn->close();
?>

This will echo out all results matching what you're asking for. You would just change the end echo statements to match the names of what you have in your database.

This answer here provides an excellent way to use the MySQLi example above as a prepared statement (similar to the first PDO example I gave). https://stackoverflow.com/a/750686/2374753

Community
  • 1
  • 1
ddonche
  • 1,065
  • 2
  • 11
  • 24
  • I don't use PDO, can you write me a simple query how to display in page only category row? Thanks – Mile Mar 01 '15 at 15:07
  • You might be able to understand mysqli instead of PDO. I've updated my answer to include a sample. – ddonche Mar 01 '15 at 16:07