Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #16  
Old 04 Dec 2014, 23:12
vBNinja's Avatar
vBNinja vBNinja is offline
 
Join Date: May 2011
Originally Posted by kh99 View Post
...and reverse the keys and values, then you can use isset() to check if the country is there, and you don't need to do a search.
What about in_array() ?
__________________
PM me for Custom Mod Requests/Work
Reply With Quote
  #17  
Old 04 Dec 2014, 23:18
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Originally Posted by vBNinja View Post
What about in_array() ?
Yeah, but then you'd still have to get the key (since that's what the function returns). There is a function whose name I can't remember that searches an array and returns the key. But I was under the impression that using a key to access an array was fast (like it was a hash table or something), so if that's true then it would be faster to reverse them.
Reply With Quote
  #18  
Old 04 Dec 2014, 23:27
vBNinja's Avatar
vBNinja vBNinja is offline
 
Join Date: May 2011
Originally Posted by kh99 View Post
Yeah, but then you'd still have to get the key (since that's what the function returns). There is a function whose name I can't remember that searches an array and returns the key. But I was under the impression that using a key to access an array was fast (like it was a hash table or something), so if that's true then it would be faster to reverse them.
I think you're talking about array_search which returns the key
__________________
PM me for Custom Mod Requests/Work
Reply With Quote
  #19  
Old 04 Dec 2014, 23:44
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Originally Posted by vBNinja View Post
I think you're talking about array_search which returns the key
lol, yeah, that's the one. I guess I should be able to remember that.
Reply With Quote
  #20  
Old 04 Dec 2014, 23:48
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Real name: James
With JSON you can get the contents on other sites. This is how many Streaming service APIs work. It's simply an ordered list. They keep it updated, whereas if I were to create one it'd be edited every time. I considered switching the keys and such but meh, I'm not sure how much it will make a difference.

I did switch to array_search though.
Reply With Quote
  #21  
Old 04 Dec 2014, 23:57
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Originally Posted by KGodel View Post
With JSON you can get the contents on other sites. This is how many Streaming service APIs work. It's simply an ordered list. They keep it updated, whereas if I were to create one it'd be edited every time. I considered switching the keys and such but meh, I'm not sure how much it will make a difference.

I did switch to array_search though.
I think you're right, it's a relatively small array so it won't make a lot of difference. And that json thing is cool, I hadn't really seen that before.

Not to criticize the other guys who are being helpful, but I didn't want to rewrite all your code for you because you didn't ask. But one thing I think I would do is change the function so it only gets the array once and saves it in a static or a global variable. That way at least you aren't getting it from a remote server once for each post.

Edit : BTW, there's also a function that swaps keys and values, but I can't remember what that one's called either.
Reply With Quote
  #22  
Old 05 Dec 2014, 00:01
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Real name: Chris
Or you can write a cron job, t get it once a day, or weekly, then save that in a static or a global variable.
__________________
You can get access to my 180 mods for vB 3.6 - 4.x at The Admin Zone as well as the professional support you are used to. New vBulletin Spider Definitions, vBulletin Spiders List Hits 1000 Spiders! ​ OzzModz down. Site has had a data breach, checking how the intrusion happened. Change your PW if you use the same one on my site and others.
Reply With Quote
  #23  
Old 05 Dec 2014, 00:31
vBNinja's Avatar
vBNinja vBNinja is offline
 
Join Date: May 2011
Originally Posted by KGodel View Post
With JSON you can get the contents on other sites. This is how many Streaming service APIs work. It's simply an ordered list. They keep it updated, whereas if I were to create one it'd be edited every time. I considered switching the keys and such but meh, I'm not sure how much it will make a difference.

I did switch to array_search though.
Im pretty sure everyone here knows how json works. I would create a cron or fetch it on demand but I see no point in this situation since it is countries and i don't think a country is added/removed as often
Another thing to think about is what happens if the server you're fetching from is down? Well so will your "plugin"
__________________
PM me for Custom Mod Requests/Work
Reply With Quote
  #24  
Old 05 Dec 2014, 00:33
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Real name: Chris
Yup, that is why I suggested getting the info in a cron.
__________________
You can get access to my 180 mods for vB 3.6 - 4.x at The Admin Zone as well as the professional support you are used to. New vBulletin Spider Definitions, vBulletin Spiders List Hits 1000 Spiders! ​ OzzModz down. Site has had a data breach, checking how the intrusion happened. Change your PW if you use the same one on my site and others.
Reply With Quote
  #25  
Old 05 Dec 2014, 00:46
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Real name: James
Do I simply need to define a global variable in the cron itself and save it?
Reply With Quote
  #26  
Old 05 Dec 2014, 02:05
nerbert nerbert is offline
 
Join Date: May 2008
If you can get it into the form of a php array you could serialize it and store it in datastore. Is it available as such an array? I could get some code for storing in datastore.

Also, did you see my post in the country flags thread? I have small flags for all countries. Not sure how up to date it is though

Last edited by nerbert; 05 Dec 2014 at 02:12.
Reply With Quote
  #27  
Old 05 Dec 2014, 02:20
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Real name: James
I was able to get a set that matches the list pretty well. I can get the array and serialize it yes.
Reply With Quote
  #28  
Old 05 Dec 2014, 02:31
nerbert nerbert is offline
 
Join Date: May 2008
To store in datastore

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


You need a plugin in "init_startup"

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Then the array should be available as $vbulletin->countries

--------------- Added 05 Dec 2014 at 03:09 ---------------

Originally Posted by kh99 View Post
Edit : BTW, there's also a function that swaps keys and values, but I can't remember what that one's called either.
array_flip()

http://www.w3schools.com/php/func_array_flip.asp
Reply With Quote
  #29  
Old 05 Dec 2014, 19:18
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Real name: James
I decided to save the codes to a DB where I can add/edit as I please. Is there a way to get them as you did in the init_startup without using datastore, or by using datastore some other way? Right now I have:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #30  
Old 05 Dec 2014, 21:35
nerbert nerbert is offline
 
Join Date: May 2008
Well, I think init_startup is as good a place to run your SELECT query as any (provided it's not too early, before the connection to the database is created), but showthread_start would work too. Theoretically you can edit the contents of datastore but it's stored as a compressed blob that's hard to read.

As for your flag images have you considered a country flag sprite? I'm working on converting a project to use sprites instead of images. There are several such sprites open source to download.
Reply With Quote
Reply



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

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


New To Site? Need Help?

All times are GMT. The time now is 05:32.

Layout Options | Width: Wide Color: