We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44891
    • 35 Posts
    I can't figure out why the query in the code beneath just executes one time (and one time only). The setup is very basic for the sake of clarity. First I generate the letters of the alphabet. When you click a letter for the first time the code executes just fine and you get a list of companynames. But when you click a second time on a letter, nothing happens. As soon as I adjust the code in Modx and save the file, again, one time execution.
    I'm on Modx 2.2.9. and the name of the php snippet is CompanyName, [[CompanyName]] Any thoughts about this weird behavior?
    Non-working version in Modx: http://www.mysite.com/modx/index.php?id=5&letter=G
    Working version, outside of Modx: http://www.mysite.com/testing/index.php?letter=G

            $arrList = array_merge(array('0-9'), range('A', 'Z'));
            foreach ($arrList as $value) {
              echo '<a href="http://www.mysite.com/modx/index.php?id=5&letter=' . $value . '">' . $value . '</a> ';
            }
    		
            echo '<p>';
            echo '<p>Press letter</p>';
         
            $host = 'localhost'; //your host
    		$username = 'MyUsername'; //your username
    		$password = 'MyPassword'; //your password
    		$database = 'Whatever'; //your database name
    		$connect = mysql_connect($host,$username,$password); //connect to the mysql database
    		mysql_query("SET NAMES 'utf8'");
            mysql_select_db($database, $connect);
            
    		if (isset ($_GET['letter'])) {
    			$sql = "SELECT * FROM Customers WHERE CompanyName LIKE '" . mysql_real_escape_string($_GET['letter']) . "%' ORDER BY CompanyName";
    			
            }
            
    		//store result
            $result = mysql_query($sql) or die("Couldn't execute query");
            if ($result && mysql_num_rows($result) >= 1) {
    			while ($row = mysql_fetch_array($result)) {
    				echo '<br />' . $row['CompanyName'] . '</a> | ';
    			}
            }
    		
            mysql_close($connect);
            //close the connection
    [ed. note: strooman last edited this post 12 years, 10 months ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Have you tried calling your snippet uncached?
       [[!CompanyName]]
        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
        • 44891
        • 35 Posts
        Quote from: sottwell at Nov 23, 2013, 10:27 PM
        Have you tried calling your snippet uncached?
         [[!CompanyName]]

        Right on the nail. Just one exclamation mark causing me headaches. Thanks.