Boldonglen Posted April 25, 2011 Share Posted April 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/ Share on other sites More sharing options...
wildteen88 Posted April 25, 2011 Share Posted April 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1205996 Share on other sites More sharing options...
Boldonglen Posted April 25, 2011 Author Share Posted April 25, 2011 Yes i do have a brand field in my products table. I was thinking of using your first method however i was worried incase there was any way of the customer to hack into the database as they would have access to the query. Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1206000 Share on other sites More sharing options...
wildteen88 Posted April 25, 2011 Share Posted April 25, 2011 This is why it is important to verify/sanitize any input from the user. If you do this properly then attackers will not be able to hack into your database. Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1206001 Share on other sites More sharing options...
Boldonglen Posted April 25, 2011 Author Share Posted April 25, 2011 Ok thanks a lot for your help. Ill mess around with my code and see if i can come up with anything that works if not ill leave a message on here. Again thanks. Boldonglen Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1206008 Share on other sites More sharing options...
Boldonglen Posted April 27, 2011 Author Share Posted April 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1206675 Share on other sites More sharing options...
Boldonglen Posted April 27, 2011 Author Share Posted April 27, 2011 Could anyone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1206874 Share on other sites More sharing options...
wildteen88 Posted April 27, 2011 Share Posted April 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1207018 Share on other sites More sharing options...
Boldonglen Posted April 27, 2011 Author Share Posted April 27, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1207131 Share on other sites More sharing options...
gizmola Posted April 27, 2011 Share Posted April 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1207204 Share on other sites More sharing options...
Boldonglen Posted April 27, 2011 Author Share Posted April 27, 2011 Yes the list of brands will be static they will not change they will be at the side of the website for the user to click on. The user does not have an input to what brand they have selected however im still unsure of how i would code the links. Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1207258 Share on other sites More sharing options...
gizmola Posted April 27, 2011 Share Posted April 27, 2011 We already suggested to you the standard way to do this. I don't know what more we can say to you at this point. It's almost like you are saying you don't know what a link is, or how it works. Quote Link to comment https://forums.phpfreaks.com/topic/234679-creating-brand-web-pages-using-querys/#findComment-1207260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.