Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 6th, 2008, 12:27 AM   #11
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 437
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Re: Need Help from Foreigners

Quote:
Originally Posted by lectricpharaoh View Post
It says I'm visiting from Vietnam (I'm not). The ip2nation page gets it right, and says I'm in Canada, so it looks like you've still got a bit of work to do on it, grim. good luck.
Ahh garbage.

Alright, let me see if anyone can see why it would be producing errors by posting the code here:
PHP Syntax (Toggle Plain Text)
  1. <pre>
  2. <?php
  3. require_once('Mimesis.php');
  4.  
  5. $cwd = realpath(dirname(__FILE__));
  6. $tableName = 'ip2nation';
  7.  
  8. $mimesis = new Mimesis($cwd, $tableName, 'ts_' . $tableName);
  9.  
  10.  
  11. $ip = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']));
  12.  
  13. $code = $mimesis->query();
  14. print_r($code);
  15. foreach($code as $key => $value)
  16. if(bccomp($key, $ip) < 0){
  17. $code = $value['code'];
  18. break;
  19. }
  20.  
  21. $tableName .= 'countries';
  22.  
  23. $mimesis = new Mimesis($cwd, $tableName, 'ts_' . $tableName);
  24.  
  25. $code = reset($mimesis->getRow($code, $code)); // This only retrieves one row despite the fact that I pass two parameters
  26.  
  27. echo $code['country'];
  28. ?>
  29. </pre>
The code listed on ip2nation is
PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $server = ''; // MySQL hostname
  4. $username = ''; // MySQL username
  5. $password = ''; // MySQL password
  6. $dbname = ''; // MySQL db name
  7.  
  8.  
  9. $db = mysql_connect($server, $username, $password) or die(mysql_error());
  10. mysql_select_db($dbname) or die(mysql_error());
  11.  
  12. $sql = 'SELECT
  13. c.country
  14. FROM
  15. ip2nationCountries c,
  16. ip2nation i
  17. WHERE
  18. i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
  19. AND
  20. c.code = i.country
  21. ORDER BY
  22. i.ip DESC
  23. LIMIT 0,1';
  24.  
  25. list($countryName) = mysql_fetch_row(mysql_query($sql));
  26.  
  27. // Output full country name
  28. echo $countryName;
  29.  
  30. ?>
Again I'm not an SQL aficionado, but I presume that what this sql statement returns is all the entries which are less than the ip in $_SERVER['REMOTE_ADDR'], sorts them in a decreasing manner and then takes the first entry from that sort. Am I mistaken? I believe that is the behavior my code is reproducing. The results that the query method yields in my code are already sorted in a descending manner and all rows are unique.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Aug 6th, 2008, 4:06 AM   #12
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 398
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Re: Need Help from Foreigners

Works for me.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Aug 6th, 2008, 10:10 AM   #13
JD-Salinger
Unknown
 
JD-Salinger's Avatar
 
Join Date: Apr 2008
Location: unknown
Posts: 87
Rep Power: 1 JD-Salinger is on a distinguished road
Re: Need Help from Foreigners

Quote:
Originally Posted by xavier View Post
Works for me.
i dont know php... but i guess its in the database... since electricpharaoh is the only one who got wrong output... or i think he's using a proxy
__________________
-------------------------------------------------------------------------
I thought what I'd Do was, I'd pretend to be one of those deaf mutes
------------------------------------------------------------------------
JD-Salinger is offline   Reply With Quote
Old Aug 6th, 2008, 12:29 PM   #14
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 398
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
Re: Need Help from Foreigners

You could ask electricpharaoh for his IP and see what the select returns , or do some debug on the php code.
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Aug 7th, 2008, 2:03 AM   #15
rhish.franks
Programmer
 
Join Date: Feb 2008
Location: India
Posts: 58
Rep Power: 1 rhish.franks is on a distinguished road
Re: Need Help from Foreigners

it got me correct. I am from India.
rhish.franks is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC