XF 2.2 How to select data from mysql?

Robert9

Well-known member
I have

Brad, boy
Dave, boy

Kathrin, girl
Sabrina, girl


I want to show them in acp like prefixes with prefixe_groups.

Boys
  • Brad
  • Dave

Girls
  • Kathrin
  • Sabrina


Should i fetch all names and group them into arrays
1.
fetch data
=> foreach
if group == boy => to array boys
if group == girls=> to array girls

or

2.
fetch data grouped bymysql left_join with data from table goup?
But then i have a lot of not needed data in a row like

Brad, boy, goupd_id, some more group_stuff
Dave, boy, goupd_id, some more group_stuff


or
3. fetch my groups

foreach group => fetch names

or
4.
fetch names (grouped or not?)
fetch groups

push data to

groups[] => names


------------------------------

and then in template
foreach loop groups
=> foreach loop group.names



I will try to find the prefix_stuff ...
 
This is what i meant above

$teamList = $teamRepo->findTeamsForList()->with('TeamGroup', true)->fetch();

the relation_data is almost the same for all results;
maybe it is better to fetch the data in a second query instead?

fetch names grouped
fetch groups
 
There is also a method as keyedby('column_name'); and this will arrange all your data into boys and girls automaticlly as you want.
 
Something different.
Imagine you have 60 different prefixGroups and for every group 18 till 24 prefixes.
The list would be very long. Do we have any example (page) to break such a list in parts?
 
Or imagine you have 500 forums and want to choose 20.

Both cases means to filter somehow.
Try this:

To view this content we will need your consent to set third party cookies.
For more detailed information, see our cookies page.
 
Thank you.

I will solve it now by country codes (like cats and forums)
Teams will be in a country, maybe also in EU.
When a league is set to one country, i will show teams from this country to choose from.
When a league is set to europe, i show the teams from europe to choose from.
 
Such a list i meant.
If i have all european countries with first, second, maybe third league and 18 till 20 teams, the list will be very long.

xensoccer.webp



If i add a new league i want to choose the teams; but to choose from all these teams is not funny.

xensoccer2.webp
 
Best would be some ajax to choose from two fields, but i have no idea where to find such a code to learn from.
Second best would be to give the league an an area_code like [country, EU, World] then fetch the teams with such area_codes in a second step.
 
Easier way. The most time i will not work with the teams; so i will switch off all groups and choose only what i need in in this moment. :)

xensoccer4.webp
 
Hmm, next problem:

I have to save my teams for a league two times
1. serialized in table league (done), but also
2. in table league_teams (league_id, team_id)

cases:
1. no data => insert one row per (league_id, team_id) from input
2. changed team => delete wrong team, insert changed team
3. no change => do nothing

What is the best way for this?
1. delete all with league_id =x
2. insert all teams from input?

or

fetch all teams, compare to input
when changes => delete old ones, insert new ones
 
Looks like the same like to save custom_fields for forums.
Saved 1. in table forum and 2. as rows in table forum_field ...


Code:
        $structure->behaviors = [
            'XF:CustomFieldsHolder' => [
                'valueTable' => 'xf_thread_field_value',
                'checkForUpdates' => ['node_id'],
                'getAllowedFields' => function($thread) { return $thread->Forum ? $thread->Forum->field_cache : []; }
            ]

So i just use that for a table with field_id and fetch data from my "field_cache";
 
Last edited:
But when/how this behaviour is triggered?

$structure->behaviors = [
'XF:CustomFieldsHolder' => [
'valueTable' => 'xf_xensoccer_league_team',
'checkForUpdates' => ['league_id'],
'getAllowedFields' => function($league) { return $league ? $league->league_data : []; }
]
];

with the saving of the fields_cache/league_data?

Doesnt work. I save the fields_cache/league_data, but nothing happens with
 
Back
Top Bottom