Jump to content

Or selector gives error


Harmster
 Share

Recommended Posts

Hey i am trying to perform an OR selector on my Match template

My match template contains 2 fields (pagefields, single) to teams called team_1 and team_2

Now I have the following selector:

$matches = $pages->find("template=match, team_1|team_2=$teams, sort=match_time");

I retrieve the teams as following:

foreach($user->teams as $team)
{
$teams .= $team."|";
}

Above the selector ofcourse. if i echo $teams i get

1011|1014|

And if i run the code i get:

Error Exception: Not unique table/alias: 'field_team_1' (in C:\xampp\htdocs\harmsterproject\wire\core\Database.php line 118)
#0 C:\xampp\htdocs\harmsterproject\wire\core\DatabaseQuery.php(84): Database->query(Object(DatabaseQuerySelect))
#1 C:\xampp\htdocs\harmsterproject\wire\core\PageFinder.php(145): DatabaseQuery->execute()
#2 C:\xampp\htdocs\harmsterproject\wire\core\Pages.php(144): PageFinder->find(Object(Selectors), Array)
#3 [internal function]: Pages->___find('template=match,...')
#4 C:\xampp\htdocs\harmsterproject\wire\core\Wire.php(271): call_user_func_array(Array, Array)
#5 C:\xampp\htdocs\harmsterproject\wire\core\Wire.php(229): Wire->runHooks('find', Array)
#6 C:\xampp\htdocs\harmsterproject\site\templates\dashboard.php(9): Wire->__call('find', Array)
#7 C:\xampp\htdocs\harmsterproject\site\templates\dashboard.php(9): Pages->find('template=match,...')
#8 C:\xampp\htdocs\harmsterproject\site\templates\home.php(3): require_once('C:\xampp\htdocs...')
#9 C:\xampp\htdocs\harmsterproject\wire\core\TemplateF
This error message was shown because you are logged in as a Superuser. Error has been logged.

What is wrong here?

Link to comment
Share on other sites

Hi Harm,

Basically, I think it's that trailing "|" that is the problem. Try building your $teams variable like this...

$teams = implode( "|", $user->teams);

This is untested but might work. If it doesn't then just change the way you build the $teams variable slightly...

foreach($user->teams as $team)
{
 $teams .= $team."|";
}
$teams = rtrim("|", $teams); // pop off that last "|"

Hope that helps.

Link to comment
Share on other sites

I just setup something like you mention and it works flawlessly. I have user template with page field to select multiple teams. A team template to create team pages. A match template with two single page fields for tema1 and team2. If I give teams to user and create match pages with teams he is in it gives me the right matches for me.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...