Jump to content

reload category and its components


web_master

Recommended Posts

Hi,

 

I got in database table CATEGORY and table PRICE

 

CREATE TABLE `price_cat` (

`price_cat_id` INT(3) UNSIGNED NOT NULL AUTO_INCREMENT,

`price_cat_name` VARCHAR(255) NOT NULL DEFAULT '',

PRIMARY KEY (`price_cat_id`)

)

ENGINE=MyISAM

ROW_FORMAT=DEFAULT

 

---------------------------------------------------

 

CREATE TABLE `price` (

`price_id` INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,

`price_pricecat` INT(6) UNSIGNED NULL DEFAULT NULL, [here comes the category ID the price_cat_id]

`price_name` VARCHAR(255) NOT NULL DEFAULT '',

`price` FLOAT NOT NULL DEFAULT '0',

PRIMARY KEY (`price_id`)

)

ENGINE=MyISAM

ROW_FORMAT=DEFAULT

 

How can I do the query to get like this:

 

<!-- queri begin

TV [this is the category from 'price_cat' table]

Chinese TV-s 100 dollar [these are from 'price' table]

English TV-s 100 dollar

Hungarian TV-s 100 dollar

 

RADIO

Chinese radio 100 dollar

Russian radio 100 dollar

Japanese radio 100 dollar

query end -->

 

Thanx in advanced

Link to comment
Share on other sites

You need to make a JOIN, like this:

 

SELECT * FROM price_cat as c
RIGHT JOIN price p ON c.price_cat_id = p.price_pricecat

 

I don't know what programming language you work with. But you can do something like this:

 

while(.....) {

if (!isset($cat)) $cat = $row["price_cat_id"];

if ($cat != $row["price_cat_id"]) {

$cat = $row["price_cat_id"];
echo $row["price_cat_name"] . "<br />";
}

echo $row["price_name"] . " " .  $row["price"] . "<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.