We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50497
    • 30 Posts
    I need to solicit the help of some of you brilliant xPDO gurus. I'm by no means extremely proficient with xPDO or PHP for that matter. Here's my scenario. I have a table that tracks the information of a product. One of the fields in that table happens to be state availability. At this point I'm using formit2db to save the values of a new product to a table. I also have a separate table for all the state values. My schema is as follows....

    <?xml version="1.0" encoding="UTF-8"?>
    <model 
    package="memberdata" 
    baseClass="xPDOObject" 
    platform="mysql" 
    defaultEngine="MyISAM" 
    tablePrefix="mp_" 
    phpdoc-package="memberdata" 
    phpdoc-subpackage="model" 
    version="1.1">
       <object class="extUser" extends="modUser">
            <composite alias="Data" local="id" class="membersProfiles" foreign="FK_user_id" cardinality="one" owner="local" />
       </object>
       <object class="states" table="states" extends="xPDOSimpleObject">
            <field key="id" dbtype="int" precision="10" phptype="integer" null="false" index="pk"  generated="native" />
            <field key="stateName" dbtype="varchar" precision="50" phptype="string" null="true" />
            <field key="stateAbbreviation" dbtype="varchar" precision="2" phptype="string" null="true" />
            <field key="stateISO" dbtype="varchar" precision="8" phptype="string" null="true" />
            <composite alias="Members" local="id" class="memberProfiles" foreign="FK_state_id" cardinality="many" owner="local" />
            <composite alias="Companies" local="id" class="companyProfiles" foreign="FK_state_id" cardinality="many" owner="local" />
            <composite alias="Locations" local="id" class="companyLocations" foreign="FK_state_id" cardinality="many" owner="local" />
        </object>
    	<object class="markets" table="markets" extends="xPDOSimpleObject">
        	<field key="id" dbtype="int" precision="10" phptype="integer" null="false" index="pk"  generated="native" />
    		<field key="FK_member_id" dbtype="int" precision="10" phptype="integer" null="true" />
            <field key="FK_companyprofile_id" dbtype="int" precision="10" phptype="integer" null="true" />
            <field key="FK_companycontact_id" dbtype="int" precision="10" phptype="integer" null="true" />
            <field key="marketName" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
    		<field key="category" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
            <field key="marketDescription" dbtype="text" phptype="string" null="true" />
            <field key="minLimit" dbtype="int" precision="50" phptype="integer" null="true" />  
            <field key="maxLimit" dbtype="int" precision="50" phptype="integer" null="true" />
            <field key="onlineQuoteURL" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
            <field key="admittedMarket" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="nonadmittedMarket" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="underwriteAuth" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="carrier" dbtype="varchar" precision="255" phptype="string" null="true" default="" />
            <field key="appointment" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="underwriteAuth" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="tags" dbtype="text" phptype="string" null="true" />
    		<field key="statesAvail" dbtype="text" phptype="string" null="true" />
    		<field key="marketFiles" dbtype="text" phptype="string" null="true" />
            <field key="deleted" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
            <field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    		<field key="createdon" dbtype="datetime" phptype="datetime" null="true" />
    		<aggregate alias="memberMarkets" local="FK_member_id" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="companyMarkets" local="FK_companyprofile_id" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="contactMarkets" local="FK_companycontact_id" foreign="id" cardinality="one" owner="foreign" />
        </object>
        </model>


    There are actually other tables within the database and schema, but I stripped those so you wouldn't have to deal with parsing through all the information. As stated I'm using formit2db to insert new records. I have the states pulling from the state table in order to insert them into the "statesAvail" field of the markets table. I'm using multiple checkboxes and that seems to be working fine.

    I have the id value of each state inserted into the statesAvail column. I have a snippet called state form values that contains the following code...

    <?php
    $path = MODX_CORE_PATH . 'components/memberdata/';
    $result = $modx->addPackage('memberdata',$path.'model/','mp_');
    $output = '';
    $states = $modx->getCollection('states');
    foreach ($states as $state){
    if(isset($state)) {
        $stateid = $state->get('id');
    	$statename = $state->get('stateName');
    	$stateabbreviation = $state->get('stateAbbreviation');
    	$stateiso = $state->get('stateISO');
    }
    if(isset($state)){
    	$output.= '<li><input name="statesAvail[]" type="checkbox" class="selectedId" [[!+fi.statesAvail:FormItIsChecked=`' . $stateid . '`]] value="' . $stateid . '" />' . $statename . '</li>';
    }}
    return $output;


    The snippet is called in the following form...

    [[!FormIt? 
    &hooks=`spam,checkCompanyCreated,formit2fileMarketFiles,formit2db` 
    &preHooks=`db2formit`
    &prefix=`mp_`
    &packagename=`memberdata`
    &tablename=`markets`
    &classname=`markets`
    &path = `assets/documents/marketfiles/`
        &extensions = `pdf,PDF`
        &maxsize = `20971520`
    &arrayFormat=`csv`
    &arrayFields = `["statesAvail"]`
    &validate=`marketDescription:allowTags`
    ]]
    <form class="full_contact_form" action="[[~[[*id]]]]" method="post" enctype="multipart/form-data">
        <input name="nospam" type="hidden" />
        <input name="FK_member_id" type="hidden" value="[[+modx.user.id]]" />
        <input name="FK_companyprofile_id" type="hidden" value="[[!getCompanyID]]" />
        
    
    <div class="form_row clearfix">
    
         <label for="marketName">
              <span class="hm_field_name">Market Name</span>
    	  <span class="hm_requires_star">*</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Enter a descriptive name for your new market. Please be sure that it's descriptive and utilizes keywords for our search feature.
    							</span>
    						</span>
         </label>
         <input class="form_fill_fields hm_input_text" type="text" name="marketName" id="marketName" value="[[+fi.marketName]]" />
    <span class="hm_requires_star">[[!+fi.error.marketName]]</span>
    
    
    
    </div>
    
    <div class="form_row clearfix">
    
         <label for="marketDescription">
              <span class="hm_field_name">Market Description</span>
    <span class="hm_requires_star">*</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Use this area to describe your market. Provide details about what's offered with the new market. Limited HTML formatting is available for this field.
    							</span>
    						</span>
    
         </label>
         <textarea class="form_fill_fields hm_input_text" name="marketDescription" value="[[+fi.marketDescription]]" id="marketDescription"></textarea>
    
    
    </div>
    
    
    <div class="form_row clearfix">
    <div class="my_col_half">
         <label for="minLimit">
              <span class="hm_field_name">Minimum Premium</span>
    <span class="hm_requires_star">*</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Please enter the minimum premium amount for this market. This will be utilized in the advanced search options to narrow markets.
    							</span>
    						</span>
         </label>
         <input class="form_fill_fields hm_input_text" type="text" name="minLimit" id="minLimit" value="[[+fi.minLimit]]" />
    <span class="hm_requires_star">[[+fi.error.minLimit]]</span>
    </div>
    <div class="my_col_half">
         <label for="maxLimit">
              <span class="hm_field_name">Maximum Premium</span>
    <span class="hm_requires_star">*</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Please enter the maximum premium amount for this market. This will be utilized in the advanced search options to narrow markets.
    							</span>
    						</span>
         </label>
         <input class="form_fill_fields hm_input_text" type="text" name="maxLimit" id="maxLimit" value="[[+fi.maxLimit]]" />
    <span class="hm_requires_star">[[+fi.error.maxLimit]]</span>
    
    </div>
    </div>
    
    
    <div class="form_row clearfix">
    
    
         <input type="hidden" name="admittedMarket[]" value="0" />
    	<input type="checkbox" name="admittedMarket[]" value="1" [[!+fi.admittedMarket:FormItIsChecked=`1`]] > Admitted Market 
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Check only if an admitted market is available.
    							</span>
    						</span>
    <span class="hm_requires_star">[[+fi.error.admittedMarket]]</span>
    
    
         <input type="hidden" name="nonadmittedMarket[]" value="0" />
    	<input type="checkbox" name="nonadmittedMarket[]" value="1" [[!+fi.nonadmittedMarket:FormItIsChecked=`1`]] > Non-Admitted Market
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Check only if a non-admitted market is available.
    							</span>
    						</span>
    <span class="hm_requires_star">[[+fi.error.nonadmittedMarket]]</span>
    
        
         <input type="hidden" name="underwriteAuth[]" value="0" />
    	<input type="checkbox" name="underwriteAuth[]" value="1" [[!+fi.underwriteAuth:FormItIsChecked=`1`]] > Underwriting Authority
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Check only if you have underwriting authority for this market.
    							</span>
    						</span>
    <span class="hm_requires_star">[[+fi.error.underwriteAuth]]</span>
    
    
    
         <input type="hidden" name="appointment[]" value="0" />
    	<input type="checkbox" name="appointment[]" value="1" [[!+fi.appointment:FormItIsChecked=`1`]] > Appointment Required
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Check if appointment is required in order to submit, quote and/or bind for this market.
    							</span>
    						</span>
    <span class="hm_requires_star">[[+fi.error.appointment]]</span>
    
    </div>
    
    <div class="form_row clearfix">
    <div class="my_col_third">
    <label for="onlineQuoteURL">
              <span class="hm_field_name">Online Quote URL</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>If online quoting is available provide the URL for the only quoting site.
    							</span>
    						</span>
         </label>
       <input class="form_fill_fields hm_input_text" type="text" name="onlineQuoteURL" id="onlineQuoteURL" value="[[+fi.onlineQuoteURL]]" />
    <span class="hm_requires_star">[[+fi.error.onlineQuoteURL]]</span>
    </div>
    <div class="my_col_third">
    <label for="carrier">
              <span class="hm_field_name">Carrier</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>If you would like to disclose the carrier for this market enter the name of the carrier.
    							</span>
    						</span>
         </label>
       <input class="form_fill_fields hm_input_text" type="text" name="carrier" id="carrier" value="[[+fi.carrier]]" />
    <span class="hm_requires_star">[[+fi.error.carrier]]</span>
    </div>
    
    <div class="my_col_third">
    <label for="FK_companycontact_id"><span class="hm_field_name">Company Contact</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Please select a contact for this market from the dropdown. If there is no carrier selected there will be no direct contact listed for the market other than general company contact information.
    							</span>
    						</span></label>
    <select name="FK_companycontact_id" value="[[!+fi.FK_companycontact_id]]">
        <option value="[[!+fi.FK_gender_id:FormItIsSelected=`[[!getUserID]]`]]">Select a contact...</option>
        [[!companyContactFormValues]]
    </select>
    </div>
    
    </div>
    
    <div class="form_row clearfix">
    
    <label for="tags">
              <span class="hm_field_name">Keywords</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Enter keywords for this market. Each keyword should be separated by a comma (,). Keep in mind these are descriptive keywords used in the search system. Examples might include: Workers' Compensation, General Liability, Flood, etc.
    							</span>
    						</span>
         </label>
    
    <input type="text" data-role="tagsinput" class="form_fill_fields hm_input_text" name="tags" value="[[+fi.tags]]" id="tags"/><span class="validation-message">Enter keyword tags separated by commas.</span>
    
      
    
    </div>
    <div class="form_row clearfix colList">
    <label for="states">
              <span class="hm_field_name">States & Territories</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Select all states and territories where this market is available. Note that by selecting all you are including Washington D.C., Puerto Rico and the Virgin Islands.
    							</span>
    						</span>
         </label>
    <ul class="selectallOption">
    <li><input type="checkbox" id="selectall"><span style="color:green;">Select all </span></input> <span class="validation-message"> (Tick checkbox to select all states, uncheck to deselect all.)</span><li/>
    </ul>
    <ul id="quad" class="colList">
    <input name="statesAvail[]" type="hidden" />
    [[!stateFormValues]]
    </ul>
    </div>
    
    <div class=form_row clearfix">
    <div class="my_col_half">
    <label for="marketFiles">
              <span class="hm_field_name">File</span>
    <span class="hm_tooltip1 tooltip-effect1-1">
    						<span class="hm_tooltip-item1">(?)</span>
    						<span class="hm_tooltip-content1 clearfix">
    							
    							<span class="hm_tooltip-text1">
    								<i class="ico-help" style="padding-left:10px;"> </i>Upload any marketing material you have related to this market in PDF format.
    							</span>
    						</span>
    	  
         </label>
         <input class="form_fill_fields hm_input_text" type="file" name="marketFiles" id="marketFiles" value="[[+fi.marketFiles]]" />
    <span class="error">[[+fi.error.marketFiles]]</span>
    </div>
    <div class="my_col_half"> </div>
    </div>
    
    
    
    
    
    
    <div class="form_row clearfix">
    							<button type="submit" name="submit" id="submit" class="send_button large_btn" value="save">
    								<i class="ico-check3"></i>
    								<span>Add Market</span>
    							</button>
    						</div>
     
    
    </form>


    And it generates the states with checkboxes in a nice format. When the user submits the form it inserts the states in a comma separated value based on id so 1,2,3,4,5,6,etc. based on selection. All of that is based on this information in the Formit setup

    &arrayFormat=`csv`
    &arrayFields = `["statesAvail"]`


    So now for my issue. I would like to display the information back to a page, but have it link the id values which are comma separated to the actual state name for each entry.

    I can make the initial xPDO call as seen below:

    <?php
    $path = MODX_CORE_PATH . 'components/memberdata/';
    $result = $modx->addPackage('memberdata',$path.'model/','mp_');
    $output = '';
    $markets = $modx->getCollection('markets');
    foreach ($markets as $market){
    if(isset($market)) {
    	$marketName = $market->get('marketName');
    	$marketDesc = $market->get('marketDescription');
    	$states = $market->get('statesAvail');
    }
    if(isset($market)){
    	$output.= '<p> Market Name:' . $marketName . '<br/>';
    	$output.= 'Market Desc:' . $marketDesc . '<br/>';
    	$output.= 'States:' . $states . '</p>';
    
    }}
    return $output;

    And that lists the name, description and gives me the comma separated values of the id's to the page. I'm at a loss of where to go from here so that instead it would write the state values to the page instead.

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      If I'm understanding you, you want the state names instead of their IDs?

      First of all, you don't need either isset(). getCollection is guaranteed to return an array of objects (or an empty array if nothing is found). If the array is empty, the foreach won't execute.

      This may get you started:

      foreach ($markets as $market){
          $marketName = $market->get('marketName');
          $marketDesc = $market->get('marketDescription');
          $states = $market->get('statesAvail');
      
          $states = explode(',', $states);
          $stateNames = array();
          foreach($states as $state) {
             $stateObj = $modx->getObject('States', $state);
             $stateNames[] = $stateObj->get('stateName');
          }
      
          $output.= '<p> Market Name:' . $marketName . '<br/>';
          $output.= 'Market Desc:' . $marketDesc . '<br/>';
          $output.= 'States:' . implode(', ', $stateNames) . '</p>';
       
      }
      



        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 50497
        • 30 Posts
        Bob,
        Thanks so much for your response. This makes sense to me and I believe I understand what's happening within the code. However, when I load the new snippet it doesn't actually output anything.

        <?php
        $path = MODX_CORE_PATH . 'components/memberdata/';
        $result = $modx->addPackage('memberdata',$path.'model/','mp_');
        $output = '';
        $markets = $modx->getCollection('markets');
        foreach
         ($markets as $market){
            $marketName = $market->get('marketName');
            $marketDesc = $market->get('marketDescription');
            $states = $market->get('statesAvail');
        
            $states = explode(',', $states);
            $stateNames = array();
            foreach($states as $state) {
               $stateObj = $modx->getObject('states',$state);
               $stateNames[] = $stateObj->get('stateName');
            }
        
            $output.= '<p> Market Name:' . $marketName . '<br/>';
            $output.= 'Market Desc:' . $marketDesc . '<br/>';
            $output.= 'States:' . implode(', ', $stateNames) . '</p>';
         
        }


        I had to change this line
        $stateObj = $modx->getObject('States',$state);

        in your code in order for it to work. The classname isn't actually uppercase so I'm not getting any errors. However, it's not loading any content to the page.

        So I then figured I would check to see if anything was happening within the snippet and I changed the code to this:

        <?php
        $path = MODX_CORE_PATH . 'components/memberdata/';
        $result = $modx->addPackage('memberdata',$path.'model/','mp_');
        $output = '';
        $markets = $modx->getCollection('markets');
        foreach
         ($markets as $market){
            $marketName = $market->get('marketName');
            $marketDesc = $market->get('marketDescription');
            $states = $market->get('statesAvail');
        	$modx->log(modX::LOG_LEVEL_ERROR, 'Loading Markets');
        
            $states = explode(',', $states);
            $stateNames = array();
            foreach($states as $state) {
               $stateObj = $modx->getObject('states',$state);
               $stateNames[] = $stateObj->get('stateName');
        	   $modx->log(modX::LOG_LEVEL_ERROR, 'Loading States');
            }
        
            $output.= '<p> Market Name:' . $marketName . '<br/>';
            $output.= 'Market Desc:' . $marketDesc . '<br/>';
            $output.= 'States:' . implode(', ', $stateNames) . '</p>';
         
        }


        That provides this in the error log:
        [2015-06-19 05:15:43] (ERROR @ /index.php) Loading Markets
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading Markets
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        [2015-06-19 05:15:44] (ERROR @ /index.php) Loading States
        


        So it's definitely looping through the content in the appropriate order and it's looping through all the records. But, the page doesn't return any output. It's just blank.

        And then my moment of epiphany of realizing how tired I really am right now.

        What did I forget?

        return $output;


        Bob, thanks so much your solution is spot on and works perfectly. Not completely understanding PHP and xPDO I'm assuming that explode separates all the values with the comma being the delimiter and implode assembles the new values from the array separating them with a comma?
          • 3749
          • 24,544 Posts
          Glad I could help. Your description of explode() and implode() are exactly right.

          The reason for creating the temporary array with "$stateNames[] =" is just so you can use implode() to create the output line. If you added them directly with ".=", you'd have an unsightly comma at the end of the list.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting