Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyszukiwanie po rekordach
maniutek08
post
Post #1





Grupa: Zarejestrowani
Postów: 107
Pomógł: 1
Dołączył: 23.08.2009

Ostrzeżenie: (0%)
-----


Może najpierw pokaże jaka jest struktura bazy :
  1. CREATE TABLE IF NOT EXISTS `attributes` (
  2. `attribute_ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  3. `attribute_name` text COLLATE utf8_polish_ci NOT NULL,
  4. PRIMARY KEY (`attribute_ID`)
  5. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci AUTO_INCREMENT=3 ;
  6.  
  7. INSERT INTO `attributes` (`attribute_ID`, `attribute_name`) VALUES
  8. (1, 'Kolor'),
  9. (2, 'Kształt');
  10.  
  11. CREATE TABLE IF NOT EXISTS `attributevalues` (
  12. `attributevalue_ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  13. `attributevalue_attribute_ID` int(10) UNSIGNED NOT NULL,
  14. `attributevalue_value` text COLLATE utf8_polish_ci NOT NULL,
  15. PRIMARY KEY (`attributevalue_ID`)
  16. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci AUTO_INCREMENT=5 ;
  17.  
  18. INSERT INTO `attributevalues` (`attributevalue_ID`, `attributevalue_attribute_ID`, `attributevalue_value`) VALUES
  19. (1, 1, 'Czarny'),
  20. (2, 1, 'Beżowy'),
  21. (3, 2, 'Prostokąt'),
  22. (4, 2, 'Owal');
  23.  
  24. CREATE TABLE IF NOT EXISTS `offerattributes` (
  25. `offerattribute_offer_ID` int(10) UNSIGNED NOT NULL,
  26. `offerattribute_attribute_ID` int(10) UNSIGNED NOT NULL,
  27. `offerattribute_attributevalue_ID` int(10) UNSIGNED NOT NULL,
  28. UNIQUE KEY `offerattribute_offer_ID` (`offerattribute_offer_ID`,`offerattribute_attribute_ID`,`offerattribute_attributevalue_ID`)
  29. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci;
  30.  
  31. INSERT INTO `offerattributes` (`offerattribute_offer_ID`, `offerattribute_attribute_ID`, `offerattribute_attributevalue_ID`) VALUES
  32. (1, 1, 1),
  33. (1, 2, 2),
  34. (2, 1, 2),
  35. (2, 2, 4),
  36. (3, 1, 2),
  37. (3, 2, 3),
  38. (4, 1, 2),
  39. (4, 2, 4);
  40.  
  41. CREATE TABLE IF NOT EXISTS `offers` (
  42. `offer_ID` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  43. `offer_name` text COLLATE utf8_polish_ci NOT NULL,
  44. PRIMARY KEY (`offer_ID`)
  45. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci AUTO_INCREMENT=5 ;
  46.  
  47. INSERT INTO `offers` (`offer_ID`, `offer_name`) VALUES
  48. (1, 'Dywan Shaggy Garlic'),
  49. (2, 'Dywan Hetman'),
  50. (3, 'Dywan Agnus'),
  51. (4, 'Dywan Shaggy Garlic');


chodzi o odpowiednie wyszukanie rekordu Jeśli chcę znaleźć rekord o nazwie 'garlic' koloru beżowego daje takie zapytanie :
  1. SELECT * FROM offers, offerattributes, attributes WHERE offerattribute_offer_ID = offer_ID && offerattribute_attribute_ID = attribute_ID && offerattribute_attribute_ID =1 && offerattribute_attributevalue_ID =2 && offer_name LIKE '%garlic%'


zapytanie zwróci offer_ID = 4.. Jeśli chcę znaleźć rekord o nazwie 'garlic' kształtu owalnego daje takie zapytanie :
  1. SELECT * FROM offers, offerattributes, attributes WHERE offerattribute_offer_ID = offer_ID && offerattribute_attribute_ID = attribute_ID && offerattribute_attribute_ID =2 && offerattribute_attributevalue_ID =4 && offer_name LIKE '%garlic%'


zapytanie zwróci offer_ID = 4..

I teraz pytanie: jak ułozyć zapytanie aby wynikiem był offer_ID = 4 wybierając kształ owalny i kolor beżowy questionmark.gif
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 04:42