2 products with the same name found...

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
Qveon
Forum Newbie
Posts: 2
Joined: Thu Feb 05, 2004 1:40 am

2 products with the same name found...

Post by Qveon »

Ok so i am making an order form that you type in a ID number and a quantity and it will call the database and fillout the missing data and add the data to a "cart" and sometimes in my database a product from different companies has the same ID number, but i don't want to make another set of unique ID numbers just for my shop.
So how would i go about coding something that does this when i type in the ID number and hit submit:
Looks up the ID and check for duplicates
If there are any duplicates, it takes the data from the duplicate rows and puts it in a html table, then i need a way to use like a radio button to input which duplicate i want to add to the order. Then hit submit and it adds to order.
If there are not any duplicates i want it to just add to the order form.

Cause i am also trying to make one so when you search for a last name to get a Customer Id number and there are multiple names i need it to pick with a radio button and hit submit, that it takes a Variable (like the user_id) and submits that to the next page.

Also in general how do i write things where i need it to work like this:

query the DB
if #of results = 1 { add to order ]
else
{ make a table with radio buttons where i can pick which one i want and it would take a variable of my choice that was displayed (like ID number) and submit it to the next page. }

Ok sorry so long but thats for the help.
User avatar
Michael 01
Forum Commoner
Posts: 87
Joined: Wed Feb 04, 2004 12:26 am

Post by Michael 01 »

This is really more a SQL issue, and not coding.

Simply put, you should have a second ID column, and I say this for a one simple reason.

1) Having a product with the same name is confusing enough, but the ID numbers are what separate them from each other. You cannot soley depend on the ID number however because it really isnt going to tell you much other than whatever data is there for that particular ID number.
Alot of guess work can take place that way.

To simplify any SQL, and get the data that you really want, you have to set up a proper SQL table base which should involve alot of differentiating data for the same product. Such suggestions would be:

Product DB
ID number, Name of product, Model of product, Model number of product, Color, Size, Manufacturing Company, State, Product Id number, etc...

Things along those lines can make SQL queries very simple, and pinpoint acuracy.

Customer DB
customerid, phone number, address, state, age, sex, SSnumber, DLnumber, area code, email, product_purchase_log, last_purchase_date etc....

Imagine if you had twelve customers all named Jon smith...using the method of NOT having separate Id's or differentiating data, a person could easily lose track of any purchases, or worse yet, have data entered into the wrong "jon smith's" account.

In short, it all comes down to what you ask from your customer/company to properly setup a SQL, and determine the proper input/output.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Assuming each company has a unique id for each item, you could make a composite key based on company_id and product_id
Qveon
Forum Newbie
Posts: 2
Joined: Thu Feb 05, 2004 1:40 am

Post by Qveon »

No ok look. Companies send out catalogs with THEIR ID numbers. I run a distributing business and a NEED to use their numbers even if some products from different companies use the same ID number and there is a difference, the products with the same numbers WILL be in different tables and have different material_type code. Like i need this

[page 1]
I enter pt327

[page 2]
<queries>
pt327 | Heavy Blue matting | 32x20 | 3 | $5.00 | $15.00

OR i need it to do this:

[page 1]
i enter rx745

[page 2]
<queries>
Which rx745?
O | JayMar Teal | mat
O | Righten | mat
O | Tiben Oak | frame

i pick one, select the radioo button and hit submit and it takes the one i entered and puts it in the form
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

As mentioned above, this is a db design issue. You do need an extra id col. Why and what to do with it is explained here.

A good relational db design is the foundation for most php apps. If you don't get it right at the start it can be very difficult to fix later.
Post Reply