Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Mysql] Select z unią gdzie drugi select inny od pierszego, nie takie oczywiste ;)
pieto
post
Post #1





Grupa: Zarejestrowani
Postów: 227
Pomógł: 1
Dołączył: 12.05.2002
Skąd: gdańsk

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


Witam

  1. <?php
  2. $featured_query = tep_db_query("(select c.categories_id ,c.categories_image, cd.categories_name,  cd.categories_htc_desc_tag from " . TABLE_CATEGORIES . " c, categories_description cd where c.art ='0' and c.categories_id ='" . (int)$parent_category_id . "' and cd.language_id='" . (int)$languages_id . "' and  c.categories_id = cd.categories_id LIMIT 1 )
  3.  
  4. UNION (select c.categories_id,c.categories_image, cd.categories_name,  cd.categories_htc_desc_tag from " . TABLE_CATEGORIES . " c, categories_description cd, featured_categories fc where c.art ='0'  ".$categories_featured_sql ." ".$manufacturers_featured_sql." and cd.language_id='" . (int)$languages_id . "' and  fc.categories_id = c.categories_id and c.categories_id = cd.categories_id ORDER BY RAND() LIMIT 1) ");
  5. ?>


Powyzsze zapytanie wybiera dwa rekordy, dwie rozne zasady z tej samej tablicy
Czasem zdazy sie ze druga czresc zapytania wylosuje ten sam rekord co pierwsza. (wtedy go nie pokazuje)

i tu pytanie jak jak tego uniknąć ?

próbowałem tak

  1. <?php
  2. $featured_query = tep_db_query("(select c.categories_id as first_cid,c.categories_image, cd.categories_name,  cd.categories_htc_desc_tag from " . TABLE_CATEGORIES . " c, categories_description cd where c.art ='0' and c.categories_id ='" . (int)$parent_category_id . "' and cd.language_id='" . (int)$languages_id . "' and  c.categories_id = cd.categories_id LIMIT 1 )
  3.  
  4. UNION (select c.categories_id,c.categories_image, cd.categories_name,  cd.categories_htc_desc_tag from " . TABLE_CATEGORIES . " c, categories_description cd, featured_categories fc where c.art ='0' and c.categories_id <> first_cid ".$categories_featured_sql ." ".$manufacturers_featured_sql." and cd.language_id='" . (int)$languages_id . "' and  fc.categories_id = c.categories_id and c.categories_id = cd.categories_id ORDER BY RAND() LIMIT 1) ");
  5. ?>


Co skutkuje

  1. <?php
  2. 1054 - Unknown column 'first_cid' in 'where clause'
  3. ?>


Jakies propozycje ?
z góry thx
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 24.08.2025 - 16:08