I have a need to store a 4 digit number in my amember records once the payment is complete. I can do that fine. My challenge is that when I try to randomly generate the 4 digit number, and then check to make sure it is not already used, the while loop hangs. I am missing something I am sure. Here is a code snippet from my site.inc.php $rand_extension = '4233'; //set manually for testing. That number is in use $found_available_extension = false; while (! $found_available_extension) { $query_all_exten = $db->query($sql = "SELECT COUNT(*) from {$db->config[prefix]}members WHERE vipline_extension = $rand_extension "); $enten_used_num = mysql_num_rows($query_all_exten); if ($enten_used_num >= 1){ $rand_extension = rand(1000,5000); } else { $u['vipline_extension'] = $rand_extension; $found_available_extension = true; } } I would appreciate any thoughts on this.
Error is in : $enten_used_num = mysql_num_rows($query_all_exten); this will always return 1; Here is a simpler way to do what you need: PHP: do { $rand_extension = rand(1000,5000);}while($db->query_one("select count(*) from {$db->config[prefix]}members WHERE vipline_extension = $rand_extension"));
Alexander, It worked great. I had started out with something similar and grew mine while I was troubleshooting. Clearly, I am not a programmer THANK YOU very much for your continued support and assistance with amember related issues. THIS is exactly why I continue to use amember in all of my membership related projects. The product is really good and the service and support are great!