Hi,
This is more if a SQL question than directly related to ExpressionEngine. Our client hired us to upgrade their existing ExpressionEngine installation from an early version of EE2 to 2.5.2 installed by another developer. When doing this, we got an error saying the SQL was invalid. After troubleshooting we found that the error stemmed from a SQL query to show a modal to users in a specific country that was querying the exp_ip2nation table:
<?php
$sg_country = ip2long($_SERVER['REMOTE_ADDR']);
?>
{exp:query sql="SELECT country AS sg_country FROM exp_ip2nation WHERE ip < '<?php echo $sg_country; ?>' ORDER BY ip DESC LIMIT 0,1"}
{if sg_country == "gb" OR sg_country == "uk"}
<!-- code to show modal -->
{/if}
{/exp:query}The problem is that the new version doesn’t have the “ip” column; it has “ip_range_low” and “ip_range_high” so this caused the site to break.
My question is: Has anyone queried the database in a similar fashion using the new structure and how would I do it now that there are 2 columns in the database instead of the single one? If so, how would I modify the SQL above to achieve it with the new structure?
Any help would be greatly appreciated.
Thanks,
Scotty