I have a Listbox-Multiple TV which options are loaded via an @SELECT with all the available players in the website (it is a sports club website) to be added to a team.
Once all the players are selected I want to process the output of the TV so I have
a list of players linked to their individual player pages.
So I am trying this code:
<?php
$tvPlayers = $modx->getTemplateVarOutput(array("tmPlayers"),'[*id*]',$published=1);
$players = explode('||',$tvPlayers[tmPlayers]);
for ($i=0; $i<count($players); $i++) {
$player = explode(', ',$players[$i]);
$fixedPlayer = $player[1] . " " . $player[0];
$document = $modx->db->select("id", "modx_site_content", "pagetitle = '" . $fixedPlayer . "'");
$output .= $document . ",";
}
return $output;
?>
I get the players selected into $tvPlayers (they are listed as "Lastname, Firstname") that are outputed as a delimited list using "||" as the delimiter.
Then I explode them into $players and invert the name as "Firstname Lastname" because that is the way the pagetitle of the individual player name is set.
Then I do a SELECT to find the "id" of the page of each player that I will input into Ditto to have a list of linked players (could not do it with the Grid widget).
Questions:
1) The $document SELECT gives me the following output:
Resource id #17,Resource id #18,Resource id #19,Resource id #20,
instead of what I want which is something like this:
which are the page id’s.
Where are these coming from? the Resource id #x?
What’s wrong on my query?
This query works fine in phpMyAdmin:
SELECT `id` FROM `modx_site_content` WHERE `pagetitle`= 'Brenda Stevens'
and gives 39.
TIA for your help...
[SOLUTION]
Do a select, then a getRow (or getValue if you only want the first element) and then get the
result in an array that could be associative, numeric or both...
<?php
$tvPlayers = $modx->getTemplateVarOutput(array("tmPlayers"),'[*id*]',$published=1);
$players = explode('||',$tvPlayers[tmPlayers]);
for ($i=0; $i<count($players); $i++) {
$player = explode(', ',$players[$i]);
$fixedPlayer = $player[1] . " " . $player[0];
$res = $modx->db->select("id", "modx_site_content", "pagetitle = '" . $fixedPlayer . "'");
$row = $modx->db->getRow($res);
$output .= $row['id'] . ", ";
}
return $output;
?>