Jump to content

[SOLVED] Help for a noob, easy question


jbrill

Recommended Posts

Hey,

 

ok heres the deal, I have two tables in the database. One is "subcategory" it holds all the subcategory's. the field "subcat" is the name of the subcategory and the other field is "cost" which represents the cost of each subcategory.

The other table is what hold the main information about the product.

 

I want to work out an easy math equation to determine the overall price. but in order to do this:

 

if the table "products" where subcat is equal to subcat from the table "subcategory", then display (form the subcategory table) the cost for that subcategory.

 

how do i do this?

Link to comment
Share on other sites

hmmm thats the code

$result=mysql_query("select subcat, price from subcategory where subact in ( select subcat from subcategory2)");

mysql_fetch_assoc($result);

 

or may want to do the double query instead of single

$result=mysq_fetch_assoc(mysql_query('select subcat from subcategory2'));

$result=mysql_query("select subcat, price from subcategory where subact in ( ".explode(',',$result.")");

mysql_fetch_assoc($result);

 

Hmm there might be an error for i dont test those but what im giving is an idea

 

Link to comment
Share on other sites

Do you mean

<?php

$sql = "SELECT p.prod_name, s.cost
        FROM product p INNER JOIN subcategory s
            ON p.subcat_id = s.subc
        ORDER BY p.prod_name";
$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); 
while (list($prod, $cost) = mysql_fetch_row($res))
{
    echo "$prod : $cost <br />";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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