Query is giving 12 duplicates when ran

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
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Query is giving 12 duplicates when ran

Post by Extremest »

This query is giving me 12 of each name yet the company is different on each of the duplicates. Can someone tell me where I am screwing up with it.

Each table is made up like this
products = idproducts,name,category,distributor,qty,minqty.
Distributors = iddistributors,company,contact,phone.

select name,qty,minqty,company from `products`, `distributors` where category = '1'
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's a side effect from using inner join (the default of a multi-table select)

am I right in guessing that products.distributor is distributors.iddistributors ? If so, tell them to match each other in the where clause.
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Post by Extremest »

ok thanks will try that. Have another question. Is there a way to have one form and depending on what they pick it will open a different page on the submit. Instead of just one page.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Yes just use Javascript

Code: Select all

function whenTheForIsSubmitted(){

if(document.formName.fieldName.value == 'someValue')
document.formName.action = 'somepage.php';
else
document.formName.action = 'someotherpage.php';

}
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Post by Extremest »

ok I have no knowledge of java or javascript. How do I setup the form can I use the form I already have? If so how do I add that to the form?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Yes, you should be able to use the form you already have.

Go ahead and post it and I'll show you off of that.
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Post by Extremest »

I don't have it complete yet but here it is.

Code: Select all

<form action="lookup.php" method="post">
<select name = "query">
	<option>Products by Cat.</option>
	<option>View Distributors</option>
	<option>View Categories</option>
	<option>Get Order</option>
	<option>View Schnapps</option>
	<option>View </option>
	<option>Get Order</option>
	<option>Get Order</option>
	<input type="submit" value="Submit">
</select>	
</form>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You could also use the PHP page that you are posting to choose which page to show based on the user input:

Code: Select all

<?php
if (isset($_POST['user_choice']))
{
    if ($_POST['user_choice'] == 'this')
    {
        // Show THIS page
    }
    elseif ($_POST['user_choice'] == 'that')
    {
        // Show THAT page
    }
    else
    {
        // Show the other page
    }
}
?>
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Post by Extremest »

I was going to try and do that but don't know how to have it open the new page that it would need.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

PHP is your better bet. Search for the header function or redirect here in the forum. We have plenty of examples. :)
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Post by Extremest »

Thank you very much. That worked out perfect now to finish up some of my code.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Does the process need to actually open and entirely new page or can it select a different included portion of the page to load. If it just a matter of showing HTML1, HTML 2, etc you can build the HTML modules and depending on the user selection include what they want.

If it's a matter of processing you can still do that, just handle the processing within the scope of the if...elseif...else brackets.
Extremest
Forum Commoner
Posts: 84
Joined: Mon Aug 29, 2005 12:39 pm

Post by Extremest »

It has to open a completely different page. I am using a switch to check the value of the form and then redirecting to the page I need or executing the query I need. Will work it all out gradually but so far the inventory site I am working on for my bar is working pretty good.
Post Reply