azpage Posted May 23, 2005 Author Report Share Posted May 23, 2005 (edited) Kaads varbuut vareetu pateikt, kaa notiek meklēšana šajā lapā : http://www.travellatvia.lv/8/23/ ? Princips tur taads pats. Domaju ka datubazes struktura ir tada pati, jo kaa gan savaadak. Edited May 23, 2005 by azpage Link to comment Share on other sites More sharing options...
bubu Posted May 23, 2005 Report Share Posted May 23, 2005 (edited) Kāpēc tu domā ka tur tāda pati struktūra? Un kāpēc tur vispār tiek izmantota SQL db? varbūt viss uz teksta failiem glabājas :P Nonācu pie šāda kverija: SELECT ieraksti.title AS title FROM ieraksti, ( SELECT ieraksti.id AS id, COUNT(*) AS sk FROM ieraksti JOIN vert1 ON ier_id=ieraksti.id WHERE vert1_config_id IN (1,3) GROUP BY ieraksti.id) AS tmp ON ieraksti.id=tmp.id WHERE tmp.sk=2; Tāds der? Edited May 23, 2005 by bubu Link to comment Share on other sites More sharing options...
azpage Posted May 23, 2005 Author Report Share Posted May 23, 2005 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ON ieraksti.id=tmp.id WHERE tmp.sk=2' at line 6 Varbuut ir iespejama kaada alternatiiva, tiesham neviens nav saskaries ar shadu probleemu ? Link to comment Share on other sites More sharing options...
bubu Posted May 23, 2005 Report Share Posted May 23, 2005 Ui, bišķu nokļūdījos kopējot. Pareizi ir šādi te: SELECT ieraksti.title AS title FROM ieraksti JOIN ( SELECT ieraksti.id AS id, COUNT(*) AS sk FROM ieraksti JOIN vert1 ON ier_id=ieraksti.id WHERE vert1_config_id IN (1,3) GROUP BY ieraksti.id) AS tmp ON ieraksti.id=tmp.id WHERE tmp.sk=2 Link to comment Share on other sites More sharing options...
azpage Posted May 26, 2005 Author Report Share Posted May 26, 2005 Liels paldies bubu Tev par paliidziibu, tas viss stradaaja. Tikai nju es esmu strupceljaa, nezinu kaa, lai tiek galaa shoreiz pieliekot klat vel vienu tabulu. Tabulas: places +----+-------------+ | id | dir | +----+-------------+ | 9 | dir1 | | 10 | albertadiki | | 11 | zebrus | +----+-------------+ fishes +----+----------+--------------+ | id | place_id | fish_type_id | +----+----------+--------------+ | 12 | 9 | 7 | | 11 | 9 | 8 | | 15 | 10 | 1 | | 13 | 10 | 2 | | 14 | 10 | 3 | | 19 | 11 | 1 | | 16 | 11 | 2 | | 17 | 11 | 3 | | 18 | 11 | 10 | +----+----------+--------------+ services +----+----------+------------------+ | id | place_id | service_group_id | +----+----------+------------------+ | 10 | 9 | 1 | | 11 | 10 | 1 | | 12 | 10 | 1 | | 13 | 10 | 6 | | 14 | 11 | 1 | +----+----------+------------------+ piemeram "1" noziimee "makšķerēšana", "6" - "pirts" Uzdevums ir atlasiit vietu direktorijas "dir", kuras satur lietotaja mekleshanas formaa ar chekbox paliidziibu izveleetas zivis un pakalpojumus, piemeram: es izvelos pakalpojumu "makšķerēšana" (service_group_id = 1) un no zivīm izvēlos "karpas" (fish_type_id = 1), "līdakas" (fish_type_id = 2), "lashi" (fish_type_id=10) un rezultaataa tiek atgriezta vieta ar ID = 11, dir = zebrus, jo citiem tabulas "places" ierakstiem nav zvis tips ar ID = 10. Meginaaju apvienot vairakus jonus, bet neizdevas. Ar zivim viss kartiibaa, bet ar pakalpojumiem ne, jo ja katrai vietai vareja but tikai vienu reizi datubazee ierakstits zivju tipa id, tad pakalpojumos vairakas reizes (kaa redzams tabulaa service_group_id=1 vienai vietai ir 2 reizes), piem makskereshana karpu diki, makskereshana lidaku diikii. Buushu pateicis par jebkuru interneta adresi vai kadu citu pamacibu vai sql pieprasijumu. Man diemzhem neizdevas atrast risinajumu. Link to comment Share on other sites More sharing options...
bubu Posted May 26, 2005 Report Share Posted May 26, 2005 Neiebraucu, ar ko atšķirās tās services no fishiem? Katrai vietai var būt piesaistīta viena vai vairāk fishu/services, un arī otrādi - viena service/fishs var būt piesaistīts vairākām vietām. Jāpieliek vēlviens subkverijs un WHERE nosacījumā vēlviens AND ar to atrasto service skaitu. Link to comment Share on other sites More sharing options...
azpage Posted May 26, 2005 Author Report Share Posted May 26, 2005 SELECT places.dir FROM places JOIN ( SELECT places.id AS id, COUNT(*) AS sk FROM places JOIN fishes ON fishes.place_id=places.id WHERE fishes.fish_type_id IN (1,2) GROUP BY fishes.place_id ) AS tmp ON places.id=tmp.id JOIN ( SELECT places.id AS id, COUNT(*) AS sk FROM places JOIN services ON services.place_id=places.id WHERE services.service_group_id IN (1) GROUP BY services.place_id ) AS tmp2 ON places.id=tmp2.id WHERE tmp.sk=2 AND tmp2.sk=1 Shim vaicajumam itkaa vajadzeeja atgriezt gan vietu ar ID=10, gan ar ID=11, jo pakalpojuma grupa ar ID = 1 ir tam abam un zivis ar ID=1 un ID=2 ar abam ir, bet atgriez tikai vietu ar ID=11. Link to comment Share on other sites More sharing options...
azpage Posted May 26, 2005 Author Report Share Posted May 26, 2005 Neiebraucu, ar ko atšķirās tās services no fishiem? Katrai vietai var būt piesaistīta viena vai vairāk fishu/services, un arī otrādi - viena service/fishs var būt piesaistīts vairākām vietām. Jāpieliek vēlviens subkverijs un WHERE nosacījumā vēlviens AND ar to atrasto service skaitu. 18053[/snapback] Itkaa teoretiski atskiribu nav, bet vaicajums manuprat kad njemt to skaitu ar funkciju COUNT, taakaa service_group_id ar vertibu "1" vienai vietai ir 2 reizes, tad arii skaits ir savadaks. Link to comment Share on other sites More sharing options...
bubu Posted May 26, 2005 Report Share Posted May 26, 2005 Aizvieto WHERE tmp.sk=2 AND tmp2.sk=1 ar WHERE tmp.sk>=2 AND tmp2.sk>=1 Link to comment Share on other sites More sharing options...
azpage Posted May 26, 2005 Author Report Share Posted May 26, 2005 Bet vai tad nevar buut taa ka viena service_group_id skaits var nosegt citu, ja to ir parak daudz vienadu, tad sanak, ka var arii atrast places, kuram nav kada no izveleetaa services. Ceru, ka saprati ko domaaju Link to comment Share on other sites More sharing options...
azpage Posted June 10, 2005 Author Report Share Posted June 10, 2005 Kaads nevareetu pateikt interneta adresi, kur var samekleet informaaciju kaa sataisiit mekleeshanas formu, kas izvada araa visas tas vietas (Posted 26. May, 2005 - 14:05 - tabulu struktura), kuras atbilst VISIEM atjekseetajiem checkboxiem ? Esmu izmeklejis googli, atradu tikai expert-exchange, tachu tur pa maksu. Droshi vien ar nepareiziem segvardiem meginaju, neticas ka to nevar realizet ar mysql. Buushu pateicigs jebkuram, Bubu - liels paldies tev! Link to comment Share on other sites More sharing options...
azpage Posted June 10, 2005 Author Report Share Posted June 10, 2005 Aizvieto WHERE tmp.sk=2 AND tmp2.sk=1 ar WHERE tmp.sk>=2 AND tmp2.sk>=1 18065[/snapback] Piemers: vieta, kura piedaavaa 4 pakalpojumus - COPE karpu diki, COPE lidaku diki, COPE forelju dikit un PIRTS. Shii vieta piedaavaa 4 pakalpojumus, tachu ir divas pakalpojumu grupas - COPE un PIRTS. Lietotajs formaa, kur redzamas visas pakalpojumu grupas: COPE PIRTS TELSHU VIETA LAIVU IRE NAKSNOSHANA MAJINJAS No shim grupam lietotajs izvelas divas - COPE un TELSHU VIETAS. Pielietojot selectus kas shajaa forumaa aprakstiti, tiks izvadiita vieta, kura nepiedaavaa TELSHU VIETAS, taadeel, ka piemera vietai ir 3 pakalpojumi zem grupas COPE un lidz ar to izvadas tapat jo tmp.sk>=2 Link to comment Share on other sites More sharing options...
Recommended Posts