Jump to content

Creating brand web pages using querys


Boldonglen

Recommended Posts

I have designed and created a ecommerce website that allows the user to add products to a shopping cart and for the admin to edit the inventory list. However i would like to have a navigational bar on the website where the user can choose a brand of product and the webpage shows only that brand. I know i can do this by using the WHERE command in a query however would i have to make a separate web page for each brand?

 

Thanks Boldonglen

Link to comment
Share on other sites

I assume you are storing the brand name of each product in a field called brand in your products table. If so maybe use a query like this

SELECT * FROM products WHERE brand="$brand_name"

 

Or if you don't have a brand field. You could perform search on the product name field something like

SELECT * FROM products WHERE product_name LIKE %$brand_name%"

 

It all depends on how you are storing your products. I cannot give a specific answer really.

 

Link to comment
Share on other sites

I have tried messing around with my code but i cannot find a way of storing information after the user clicks a link. For example i have a list of brands on my website and each one has a hyperlink. When the user clicks the hyperlink i would like the name of that brand to be stored into a variable so that i can use the variable within the query. Could anyone help me out with this problem. Or recommend another solution to how i could show the products that are of the particular brand that the user clicks.

 

Thanks Boldonglen

Link to comment
Share on other sites

How are creating your links? Can you show an example.

 

I'd make your links like this

<a href="brand.php?brand=$brand_name">$brand_name</a>

 

Now in brand.php you can get the brand via the $_GET['brand'] variable.

 

You shouldn't be creating separate php files for each brand.

Link to comment
Share on other sites

Im a little confused with the code that you supplied im not 100% with PHP The links that i have created are on every web page i have created and would like them all to link to one web page named product_list and for that page to be populated with the products of the brand selected. The code for my links are:

 

<p><a href="product_list">Brand1</a></p>
          <p><a href="product_list">Brand2</a></p>
          <p><a href="product_list">Brand3</a> </p>

Link to comment
Share on other sites

The way you do this, as Wildteen suggested is to have your product_list.php script utlize a url parameter of brand.

 

Then get this parameter inside product_list.php using:

 

$brand = $_GET['brand'];

 

As he mentioned you need to handle a couple of possibilities:

 

- Did they try a sql injection?

- Did they go directly without a brand= parameter.

- Did they specify an invalid brand

 

So you need some code to check for these issues and deal with them as you desire.  A typical solution might be to display an error page, or to default the brand to something you desire.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.