Kaupade otsing poes (tootekataloog) kaubad: id nimetus kaubagrupi_id hind kaubagrupid: id grupinimi nt kaubagrupid 1 tellised 2 katusematerjal 3 vineer kaubad 1 ahjutellis 1 8.20 2 fassaaditellis 1 7.50 3 bituumenrull 2 520.00 CREATE TABLE kaubagrupid( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, grupinimi VARCHAR(255) ); INSERT INTO kaubagrupid(grupinimi) VALUES ('tellised'); INSERT INTO kaubagrupid(grupinimi) VALUES ('katusematerjal'); mysql> SELECT * FROM kaubagrupid; +----+----------------+ | id | grupinimi | +----+----------------+ | 1 | tellised | | 2 | katusematerjal | +----+----------------+ 2 rows in set (0.00 sec) CREATE TABLE kaubad( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, nimetus VARCHAR(255), kaubagrupi_id INT, hind DECIMAL(10, 2) ); INSERT INTO kaubad (nimetus, kaubagrupi_id, hind) VALUES ('ahjutellis', 1, 8.20); INSERT INTO kaubad (nimetus, kaubagrupi_id, hind) VALUES ('fassaaditellis', 1, 7.50); INSERT INTO kaubad (nimetus, kaubagrupi_id, hind) VALUES ('bituumenrull', 2, 520); mysql> SELECT * FROM kaubad; +----+----------------+---------------+--------+ | id | nimetus | kaubagrupi_id | hind | +----+----------------+---------------+--------+ | 1 | ahjutellis | 1 | 8.20 | | 2 | fassaaditellis | 1 | 7.50 | | 3 | bituumenrull | 2 | 520.00 | +----+----------------+---------------+--------+ SELECT nimetus, grupinimi, hind FROM kaubad, kaubagrupid WHERE kaubad.kaubagrupi_id=kaubagrupid.id; mysql> SELECT nimetus, grupinimi, hind -> FROM kaubad, kaubagrupid -> WHERE kaubad.kaubagrupi_id=kaubagrupid.id; +----------------+----------------+--------+ | nimetus | grupinimi | hind | +----------------+----------------+--------+ | ahjutellis | tellised | 8.20 | | fassaaditellis | tellised | 7.50 | | bituumenrull | katusematerjal | 520.00 | +----------------+----------------+--------+ mysql> SELECT nimetus, hind FROM kaubad WHERE hind<10.00; +----------------+------+ | nimetus | hind | +----------------+------+ | ahjutellis | 8.20 | | fassaaditellis | 7.50 | +----------------+------+ mysql> SELECT nimetus, hind FROM kaubad WHERE nimetus LIKE '%tellis%'; +----------------+------+ | nimetus | hind | +----------------+------+ | ahjutellis | 8.20 | | fassaaditellis | 7.50 | +----------------+------+ SELECT nimetus, grupinimi, hind FROM kaubad, kaubagrupid WHERE kaubad.kaubagrupi_id=kaubagrupid.id AND nimetus LIKE '%tellis%'; mysql> SELECT nimetus, grupinimi, hind -> FROM kaubad, kaubagrupid -> WHERE kaubad.kaubagrupi_id=kaubagrupid.id -> AND nimetus LIKE '%tellis%'; +----------------+-----------+------+ | nimetus | grupinimi | hind | +----------------+-----------+------+ | ahjutellis | tellised | 8.20 | | fassaaditellis | tellised | 7.50 | +----------------+-----------+------+ Veateade: Column 'id' in field list is ambiguous prepare("SELECT kaubad.id, nimetus, grupinimi, hind FROM kaubad, kaubagrupid WHERE kaubad.kaubagrupi_id=kaubagrupid.id"); //echo $yhendus->error; $kask->bind_result($id, $nimetus, $grupinimi, $hind); $kask->execute(); $hoidla=array(); while($kask->fetch()){ $kaup=new stdClass(); $kaup->id=$id; $kaup->nimetus=htmlspecialchars($nimetus); $kaup->grupinimi=htmlspecialchars($grupinimi); $kaup->hind=$hind; array_push($hoidla, $kaup); } return $hoidla; } ?>
Array ( [0] => stdClass Object ( [id] => 1 [nimetus] => ahjutellis [grupinimi] => tellised [hind] => 8.20 ) [1] => stdClass Object ( [id] => 2 [nimetus] => fassaaditellis [grupinimi] => tellised [hind] => 7.50 ) [2] => stdClass Object ( [id] => 3 [nimetus] => bituumenrull [grupinimi] => katusematerjal [hind] => 520.00 ) )
Nimetus | Kaubagrupp | Hind |
---|---|---|
=$kaup->nimetus ?> | =$kaup->grupinimi ?> | =$kaup->hind ?> |