We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26182
    • 164 Posts
    Hi,

    I was wondering if there’s any way to automate the creation of html documents or to display results from the mysql database on a web page? That is once someone signs up to a web page they have a profile, and a link to their profile in the navigation under a parent directory.

    Their profile will display the row in the database that corresponds to their id.

    Any help or suggestions would be greatly appreciated.

    Thankyou very much.

    Sarah smiley

    By the way - modx is way cool wink
      • 26182
      • 164 Posts
      could I create a customized snippet and have as variables the id and a template to display the document? But how would the documents be referenced in the document tree? If there was a folder for each profile then that could feature a snippet that automatically displays the particular user’s profile when their name is selected in the navigation panel. Am I completely off the mark here?
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You would need a plugin that worked off the OnSaveWebUser event (or whatever the event is called) and created the new document when the new user gets saved, and snippets to display everything.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 23072
          • 150 Posts
          However, that could create a LOT of pages, so I’d recommend having a look at the snippet documentation to gather information together and creating a page called something like www.yoursite.com/profile.html and dropping the snippet in.

          Snippets can query databases, and so long as you don’t cache the snippet, you should easily be able to get information for the current user on one page, no matter who they are.

          Snippets and placeholders is the way forward on this one I reckon. There’s information on both on this site’s documentation, and if you need to access another database’s contents, there’s an example in the wiki too.
            Notanotherdotcom Ltd

            Web | Print | Marketing
            • 26182
            • 164 Posts
            thanks so much. I’ve opted for the snippets method. this is what i have so far:

            <table border="2" bordercolor="#FF9900" cellspacing="2" cellpadding="2">
            <tr>
            <th><font face="Arial, Helvetica, sans-serif">Name</font></th>
            </tr>
            
            <?php
            // deletestudents.php - a customised php page that works from a snippet call to list web users in the
            // database and provide functionality for the students to be deleted from the database
            // author: sarah vardy
            
            	// Establish a connection to the MySQL DBMS
            	$connection = mysql_connect("localhost", "root", "s0laspie");
            
            	// Use the modx database
            	mysql_select_db("modx", $connection);
            
            
               	// Run a query through the connection
               	$result = mysql_query("SELECT id, username FROM modx_web_users ORDER BY id", $connection);
              
               
               	//run the while loop that grabs all the web users
              	while($r=mysql_fetch_array($result)) 
               	{ 
                  	//grab the title and the ID of each user
                  	$username=$r["username"];//take out the title
                  	$id=$r["id"];//take out the id
                 
            	 	  	?><tr><td bgcolor="#CCCCCC" ><div align="center"></div>
            			<?php
            		//make the title a link
                  	echo "<a href='index.php?id=48'>$id \t $username</a>";
            		?>
            		</td>
            		</tr>
            		</div>
            		<?php
            	}   		
            ?>
            
            <?
            echo "</table>";
            ?>


            I wasn’t sure how to pass the username variable to the url that is opened that I aim to have a snippet in that reads the username and displays the appropriate entry from the database. Any advice or clues you could offer would be highly appreciated.

            Thanks very much.

            Sarah smiley
              • 26182
              • 164 Posts
              So where can placeholders be used?

              I currently have a snippet that calls my php script to display the entries. How do I get the id of the selection in this instance of code?

              Any help would be so awesome.

              Thanks muchly.

              Sarah smiley
                • 26182
                • 164 Posts
                I now have a php script being called by a snippet. The php script refers the user to a blank page where I would like the details of the user they have selected to view displayed. I have passed the id of the entry in the database to the echo statement in the php. It is tacked onto the URL of the blank html page that the user is re-directed to. i.e. http://mywebsitewithmodx.com/index.php?id=48&Uid=7

                How can I retrieve the id through a snippet to display on the user’s details on a new page?

                Thankyou for your time and I look forward to hopefully hearing back from someone about this smiley

                Sarah
                  • 21475
                  • 80 Posts
                  Hi sarah,

                  Have you tried the "ppp" snippet, that seem to do what your are looking for? ie user registration, webuser profile in a page, webuser edit profil, list of webusers, with extra fiels, and so on...

                  nicpan
                    • 26182
                    • 164 Posts
                    Hi Nicpan,

                    I tried to search for this snippet but I couldn’t find it anywhere. Could you please let me know where to find some information about this resource.

                    Cheers,


                    Sarah smiley
                      • 33337
                      • 3,975 Posts
                        Zaigham R - MODX Professional | Skype | Email | Twitter

                        Digging the interwebs for #MODX gems and bringing it to you. modx.link