Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL]Niejednoznaczna kolumna
Forum PHP.pl > Forum > Przedszkole
seweryn
Witam,

mam taki oto kod:

  1. $select = ' DISTINCT ju.id AS id
  2. , ju.name AS name
  3. , ju.username AS username
  4. , vmu.user_is_vendor AS is_vendor
  5. , vmu.perms AS perms
  6. , ft.fotograf AS fotograf
  7. , ju.usertype AS usertype
  8. , IFNULL(sg.shopper_group_name, "") AS shopper_group_name ';
  9. $joinedTables = ' FROM #__users AS ju
  10. LEFT JOIN #__virtuemart_vmusers AS vmu ON ju.id = vmu.virtuemart_user_id
  11. LEFT JOIN #__virtuemart_userinfos AS ft ON ju.id = ft.virtuemart_user_id
  12. LEFT JOIN #__virtuemart_vmuser_shoppergroups AS vx ON ju.id = vx.virtuemart_user_id
  13. LEFT JOIN #__virtuemart_shoppergroups AS sg ON vx.virtuemart_shoppergroup_id = sg.virtuemart_shoppergroup_id ';


dodałem pogrubione linie, niestety joomla zwraca komunikat:

Cytat
vmError: exeSortSearchListQuery Column 'name' in where clause is ambiguous SQL=SELECT SQL_CALC_FOUND_ROWS


Walczę z tym drugi dzień i nie mogę zrozumieć, dlaczego ta kolumna jest niejednoznaczna (występuje ona wprawdzie w dodanej przeze mnie tabeli poraz drugi, ale przecież nie wczytuję jej SELECT'em).

Bardzo proszę o pomoc.
mortus
Tyle, że błąd znajduje się gdzieś indziej, a dokładniej w klauzuli WHERE, jak głosi komunikat. Pokaż całe zapytanie, bo tutaj pokazujesz dwa niepowiązane nawet ze sobą fragmenty.
seweryn
  1. function getUserList() {
  2.  
  3. $select = ' DISTINCT ju.id AS id
  4. , ju.name AS name
  5. , ju.username AS username
  6. , vmu.user_is_vendor AS is_vendor
  7. , vmu.perms AS perms
  8. , ft.fotograf AS fotograf
  9. , ju.usertype AS usertype
  10. , IFNULL(sg.shopper_group_name, "") AS shopper_group_name ';
  11. $joinedTables = ' FROM #__users AS ju
  12. LEFT JOIN #__virtuemart_vmusers AS vmu ON ju.id = vmu.virtuemart_user_id
  13. LEFT JOIN #__virtuemart_userinfos AS ft ON ju.id = ft.virtuemart_user_id
  14. LEFT JOIN #__virtuemart_vmuser_shoppergroups AS vx ON ju.id = vx.virtuemart_user_id
  15. LEFT JOIN #__virtuemart_shoppergroups AS sg ON vx.virtuemart_shoppergroup_id = sg.virtuemart_shoppergroup_id ';
  16.  
  17. return $this->_data = $this->exeSortSearchListQuery(0,$select,$joinedTables,$this->_getFilter(),'GROUP BY vmu.virtuemart_user_id',$this->_getOrdering());
  18.  
  19. }
  20.  
  21.  
  22. /**
  23. * If a filter was set, get the SQL WHERE clase
  24. *
  25. * @return string text to add to the SQL statement
  26. */
  27. function _getFilter()
  28. {
  29. if ($search = JRequest::getWord('search', false)) {
  30. $search = '"%' . $this->_db->getEscaped( $search, true ) . '%"' ;
  31. //$search = $this->_db->Quote($search, false);
  32.  
  33. //$where = ' WHERE `name` LIKE '.$search.' OR `username` LIKE ' .$search;
  34. $where = ' WHERE `name` LIKE '.$search.' OR `username` LIKE ' .$search.' OR `email` LIKE ' .$search.' OR `fotograf` LIKE ' .$search.' OR `shopper_group_name` LIKE ' .$search;
  35. return ($where);
  36. }
  37. return ('');
  38. }


Pogrubiony tekst to moje modyfikacje. Wersja pierwotna nie posiadała tych wpisów.
bpskiba
$where = ' WHERE `ft.name` LIKE '.$search.' OR `username` LIKE ' .$search.' OR
seweryn
Przepraszam, w kodzie był błąd zamiast ft.name jest ju.name - poprawiłem już w moim poprzednim poście.

Jednak po zmianie name na ju.name otrzymuje komunikat:

Cytat
vmError: exeSortSearchListQuery Unknown column 'ju.name' in 'where clause' SQL=SELECT SQL_CALC_FOUND_ROWS
bpskiba
w tabeli #__users nie istnieje kolumna 'name'
seweryn
w tabeli #__users istnieje kolumna `name`.

W kodzie są fragmenty pogrubione, bez nich wszystko działa jak należy, po dodaniu nowych fragmentów (pogrubione), przestaje działać i zwraca wcześniej przytoczony komunikat.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.