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.]