We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14714
    • 84 Posts
    hi all, how do I display database ’members info’ into a table - ie. name, address, phone, email, website.
      • 4172
      • 5,888 Posts
      The easiest way, if you have a table named ’modx_members’: Create a snippet ’memberstable’ with:

      <?php
      $where=(isset($region))?'region="'.$region.'" ':'';
      $orderby ='name';
      $result=$modx->db->select('*',$modx->getFullTableName('members'),$where,$orderby );
      $rows=$modx->db->makeArray($result);
      
      $output='<table>';
      foreach ($rows as $row){
      $output.='<tr>';
      $output.='<td>'.$row['name'].'</td>';
      $output.='<td>'.$row['adress'].'</td>';
      $output.='<td>'.$row['phone'].'</td>';
      $output.='<td>'.$row['email'].'</td>';
      $output.='<td>'.$row['website'].'</td>';
      $output.='</tr>';
      }
      $output.='</table>';
      return $output;
      ?>


      call it with [!memberstable? &region=`north`!]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 14714
        • 84 Posts
        thanks ’Bruno17’ - the members are broken into regions would i do [!memberstable-south!] and [!memberstable-north!] ? etc
          • 4172
          • 5,888 Posts
          Do you have different tables for each region or do you have one table with field ’region’?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 14714
            • 84 Posts
            haven’t set it up yet - would like the simplest solution
              • 4172
              • 5,888 Posts
              Have changed the code a little bit for having a field ’region’
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 14714
                • 84 Posts
                thanks that’s great!
                i was thinking of using eForm to capture the members details - would that be ok?
                i would then need the member to select which region there in -would that be a specific tag?
                  • 4172
                  • 5,888 Posts
                  you can use webloginPE for userregistering and usermanagement in the frontend. It works very well for that.
                  http://modxcms.com/WebLoginPE-1593.html

                  If you do not need full usermanagement you can use of course eForm and eForm2db for getting the Datas into the database.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 14714
                    • 84 Posts
                    thanks Bruno17
                      • 14714
                      • 84 Posts
                      totally confused huh

                      i will place the code and steps i have done..

                      STEP 1. made a snipplet call eForm2db and placed this code...

                      <?php
                      function eForm2db( &$fields )
                      {
                      /*---------------------------------------------------------------
                      eForm2db
                      Version: 0.1 [Beta 1]
                      Author: pixelchutes
                      ---------------------------------------------------------------
                      Requirements:
                      eForm 1.4+
                      ---------------------------------------------------------------
                      Use:
                      - Takes validated eForm submittal data for use with the MODx DBAPI extender class.
                      - Easily process database records referencing your form submission data:
                      + INSERT new records to a table of your choice
                      + UPDATE existing records if you’d prefer
                      + DELETE records based on form submittal criteria
                      + Form a query and return its record set as XML using $modx->db->getXML
                      + Query a table’s MetaData using $modx->db->getTableMetaData, followed by an update query
                      on only the form fields that are named after table columns!
                      + and much more!
                      ---------------------------------------------------------------*/

                      // Bring needed resources into scope
                      global $modx, $table_prefix;

                      // Init our array
                      $dbTable = array(); // key = DB Column; Value = Insert/Update value

                      // Insert field/value pairs to insert/update in our table
                      $dbTable[name] = $fields[first_name].’ ’.$fields[last_name]; // Merge two form fields together
                      $dbTable[datetime] = date( ’YmdHis’, strtotime( $fields[postdate] ) ); // Massage the postdate timestamp to be MySQL insert friendly


                      // INSERT - $dbQuery = $modx->db->insert( $dbTable, $table_prefix . ’insertTableName’ );
                      // UPDATE - $dbQuery = $modx->db->update( $dbTable, $table_prefix . ’updateTableName’ );
                      // DELETE - $dbQuery = $modx->db->delete( $table_prefix . ’deleteFromTableName’, ’some_field = 1 AND name=\’’.$dbTable[name].’\’’, ’’ );
                      // etc...

                      // Run the db insert query
                      $dbQuery = $modx->db->insert( $dbTable, $table_prefix . ’insertTableName’ );

                      return true;
                      }
                      // Return empty string
                      return ’’;
                      ?>



                      STEP 2. made a snipplet called ’memberstable’ and placed this code...

                      <?php
                      $where=(isset($region))?’region="’.$region.’" ’:’’;
                      $orderby =’name’;
                      $result=$modx->db->select(’*’,$modx->getFullTableName(’members’),$where,$orderby )
                      $rows=$modx->db->makeArray($result);

                      $output=’<table>’;
                      foreach ($rows as $row){
                      $output.=’<tr>’;
                      $output.=’<td>’.$row[’suburb’].’</td>’;
                      $output.=’<td>’.$row[’centre’].’</td>’;
                      $output.=’<td>’.$row[’street’].’</td>’;
                      $output.=’<td>’.$row[’contact’].’</td>’;
                      $output.=’<td>’.$row[’phone’].’</td>’;
                      $output.=’<td>’.$row[’email’].’</td>’;
                      $output.=’<td>’.$row[’website’].’</td>’;
                      $output.=’</tr>’;
                      }
                      $output.=’</table>’;
                      return $output;
                      ?>



                      STEP 3. made a Members Form page containing this code...

                      [!eForm? &noemail=`true` &formid=`MembersForm` &eFormOnBeforeMailSent=`eForm2db` &tpl=`MembersForm` &gotoid=`57` !]


                      STEP 4. made a chunk called ’MembersForm’ with this code...
                      i think the post action should be something else?

                      <p class="error">[+validationmessage+]</p>

                      <form method="post" action="[~[*id*]~]" id="EmailForm" name="EmailForm">

                      <fieldset>
                      <h3> Your Details </h3>

                      <input name="formid" type="hidden" value="ContactForm" />

                      <label for="cfSuburb">Suburb:

                      <input name="name" type="text" class="text" id="cfSuburb" size="40" />
                      </label>


                      <label for="cfCentre">Centre:

                      <input name="name" type="text" class="text" id="cfCentre" size="40" />
                      </label>


                      <label for="cfStreet">Street:

                      <input name="name" type="text" class="text" id="cfStreet" size="40" />
                      </label>


                      <label for="cfContact">Contact:

                      <input name="name" type="text" class="text" id="cfContact" size="40" />
                      </label>


                      <label for="cfPhone">Phone:

                      <input name="name" type="text" class="text" id="cfPhone" size="40" />
                      </label>


                      <label for="cfRegion">

                      Region:</label>
                      <select name="subject" id="cfRegion" >
                      <option value="North">North</option>
                      <option value="South"> South</option>
                      <option value="West">West</option>
                      <option value="East">East</option>
                      <option value="Regional">Regional</option>
                      </select>


                      <label for="cfEmail">

                      Your Email Address:

                      <input name="email" type="text" class="text" id="cfEmail" size="40" />
                      </label>
                      <label for="cfWebsite">

                      Your Website Address:

                      <input name="email" type="text" class="text" id="cfWebsite" size="40" />
                      </label>


                      <label>

                      &nbsp;</label>
                      <input type="submit" name="contact" id="cfContact" class="formborder" value="Send" />
                      </fieldset>
                      </form>



                      STEP 5. made a test page with this code in it...

                      [!memberstable? &region=`north`!]

                      and it’s displaying this error

                      Parse error: syntax error, unexpected T_VARIABLE in /home/communit/public_html/members/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 5

                      thanks anyone that can help