Jasper Howard
Jasper Howard

Reputation: 167

How to create dynamic php content?

I am building a Website for a restaurant and since everything is stored on a MySQL Database, I need to implement the navigation logic. Everything is organized in "Cards", a card is a image with a title. Here's what I try to do: enter image description here

Because I used PHP mainly for the Database logic, I would like to keep using PHP. So, this is what I thought to do for now. I tried to store the navigation logic in this way.

$tree = array("Drinks" => array(
    "Alcholic" => array("Beers", "Vodka", "Wines"),
    "Non-Alcholic" => array("Juices", "Something Else...")
  ),
  "Food" => array(
    //...
  )
);

What I have been working for the past days is how to go from the $tree array to actually implementing the logic. I have stored all the item data on the Database already. Thanks in advance!

Upvotes: 0

Views: 55

Answers (1)

Eriks Klotins
Eriks Klotins

Reputation: 4180

For starters, if you are not building the next Amazon, use WordPress + WooCommerce, Shopify, or any other webshop platform. If you want to build from scratch, use Laravel for the basics. It will save you a lot of time and offer way more features that you will ever be able to build yourself.

To answer your question, you need to create a URL scheme to detect what your user is looking at. For example:

// to show alcoholic drinks
yoursite.com?type=alcoholic

// to show wines
yoursite.com?category=wines

//to show specific drink
yoursite.com?drink=fancy_wine_from_france

then use _GET[] array to determine what variables were passed and what content to show. E.g.

if (isset($_GET['drink']))
{
   $drink = $_GET['drink'];
   // select * from your_table where drink = '$drink'
}
if ((isset($_GET['cat']))
{
    $category = $_GET['cat'];
    // select * from your_table where drink_category = '$category' 
}

The code is to demonstrate the principle, do not use it in the production

Upvotes: 2

Related Questions