create a website product comparision query using php mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mervdsz
Forum Newbie
Posts: 2
Joined: Mon Mar 03, 2014 12:29 am

create a website product comparision query using php mysql

Post by mervdsz »

Hi

I am trying to create a simple web comparision page using php-mysql.
The web pages contains products. I would like to provide viewers with the option to compare products. Atmost 4 products should be compared at same time.
Therefore i propose to place a small checkbox next to each product to see if 4 products are selected. Once 4 products are checked and compare button is clicked the results should display in pop-up window.

How do i write the query taking into consideration the products selected ???
how do i display the results from database onto website in a pop-up page ???

my products table is as follows:
product-id
product-name
price
quantity
stock

is there a better option to do it???

im a newbie to php and also mysql.I understand SQL having worked with ORACLE databases.
Can someone please help me. Give me some ideas to work around with.
Thanks in advance.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: create a website product comparision query using php mys

Post by Celauran »

Don't use pop up windows. Seriously.

That aside, what have you written so far and where are you running into trouble?

The simplest approach, I think would be to display your summary table with the checkboxes creating an array of IDs (ie. <input type="checkbox" name="product_ids[]" value="whatever">). You could use jQuery to disable checking boxes once four are checked if you like. Once the form is submitted, it's just a question of selecting the required columns from your products table where the ID is in the $_POST['product_ids'] array.
Post Reply