Jump to content

query help....


dpabla

Recommended Posts

Here is how my Products Table is structured:

product_id    vendor_id  category_id  subcategory_id  product_name
----------    ----------  -----------  --------------  --------------
1                        1            2                  1                  Apples
2                        1            2                  1                  Oranges

Lets say the customer selected vendor named "Nike" and its vendor id = 2
Now when the products page appears, it should not display anything on products.php page because according to the products table, vendor_id only shows a 1...vice versa if a user selected "reebok" and its ID was a 2 than it would display "apples" and "oranges" on the page...I do have a vendors table that has an auto-increment where each vendor gets their unique id # where it also appears on the products table...

Here is my current query - so in a nutshell I want the query to logically pull only the products whom the variables being passed from the previous page match vendor_id # and subcategory #

Here is what I have: IF you notice, that it pulls ALL of the products and doesnt care who the vendor is...so if its vendor id = 2 than it shouldnt pull anything but it still does...
[code]<?php

$result = mysql_query("select * from products WHERE subcategory_id= {$_GET['sub_id']}");
while($r=mysql_fetch_array($result))

{

$prod_id=$r["product_id"];
$prodname=$r["product_name"];

echo "<a href='product.php?vid=" . $vid . "&cid=". $cid . "&sub_id=". $sub_id .  "&prod_id=". $prod_id . "'>" . $prodname . "</a><br>";



}

?>[/code]


I have this following query which works: However I wonder how to do a multiple GET in 1 select statement?
[code]//$result = mysql_query
//("SELECT products.subcategory_id, products.product_name FROM products
//JOIN subcategory ON products.subcategory_id = subcategory.subcategory_id
//WHERE products.subcategory_id = {$_GET['sub_id']}");[/code]

Thanks for your help!
Link to comment
https://forums.phpfreaks.com/topic/34055-query-help/
Share on other sites

Whoops sorry I am editing my first post since I saw some errors in the logic i was presenting...it wouldnt let me modify....

Here is how my Products Table is structured:

product_id    vendor_id  category_id  subcategory_id  product_name
----------    ----------  -----------  --------------  --------------
1                        1            2                  1                  Apples
2                        1            2                  1                  Oranges
3                        2            2                  1                  Bananas

Lets say the customer selected vendor named "Nike" and its vendor id = 2
Now when the products page appears, it should ONLY display Bananas and not Apples and Oranges - vice versa if a user selected "reebok" and its ID was a 1 than it would display "apples" and "oranges" on the page...I do have a vendors table that has an auto-increment where each vendor gets their unique id #...and logically if you notice at my Product table, the vendor_id #'s are manually entered with the same exact #'s in the Vendor Table

Here is my current query - so in a nutshell I want the query to logically pull only the products whom the variables being passed from the previous page match vendor_id # and subcategory # and outputs the product name

Here is what I have: IF you notice, that it pulls ALL of the products and doesnt care who the vendor is...so if its vendor id = 2 than it shouldnt pull anything but it still does...
[code]<?php

$result = mysql_query("select * from products WHERE subcategory_id= {$_GET['sub_id']}");
while($r=mysql_fetch_array($result))

{

$prod_id=$r["product_id"];
$prodname=$r["product_name"];

echo "<a href='product.php?vid=" . $vid . "&cid=". $cid . "&sub_id=". $sub_id .  "&prod_id=". $prod_id . "'>" . $prodname . "</a><br>";



}

?>[/code]


I have this following query which works: However I wonder how to do a multiple GET in 1 select statement?
[code]//$result = mysql_query
//("SELECT products.subcategory_id, products.product_name FROM products
//JOIN subcategory ON products.subcategory_id = subcategory.subcategory_id
//WHERE products.subcategory_id = {$_GET['sub_id']}");[/code]

Thanks for your help!
Link to comment
https://forums.phpfreaks.com/topic/34055-query-help/#findComment-160087
Share on other sites

Here is the code if anyone wants help obtaining 2 variables to check against a database to return results - I figured it out on my own :)

[code]$result = mysql_query("select * from products WHERE subcategory_id= {$_GET['sub_id']} AND vendor_id= {$_GET['vid']}");
while($r=mysql_fetch_array($result))[/code]
Link to comment
https://forums.phpfreaks.com/topic/34055-query-help/#findComment-160119
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.