Jump to content

[SOLVED] php-declared array vs mysql calls


Najdorf

Recommended Posts

I'm a beginner in php (forgive if my syntax is all wrong, I'll write in pseudo code) , I wanted to make a page reserved to "members", so they would use a link such as

 

mysite.com/memberpage.php?id=1678adg1e

 

I would then have to check if the id belongs to a predetermined array of strings.

 

The array of valid strings would something like 10000 different strings.

 

so then if 1678adg1e belongs to this array I would return the content, otherwise not.

 

Can i simply declare the array in the memberpage.php file? like

 

myarray=("hthrjhertj", "fgrth56465", ...)

 

or should I use sql? (the array would not need to change dynamically).

 

Another thing, as for performace goes, is the array "contains" method fast enough in this case? I figured if my myarray was pre-ordered, it would be possible to optimize the search by jumping in the middle of the array, checking if the inputted string is "greater" than the string in the middle of the array, if so jump at 3/4 of the array, if not at 1/4 and continue this way (should be much more efficient, is there a pre-built function in php to do this?)

 

Thanks very much.

Link to comment
Share on other sites

there is a php function for searching arrays array should be listed there

but i would go with mysql no questions are you sure you don't want the ability to add more pages?

and a array with 10000 strings 10 characters long would be 97kb alone in the file it would slow do the page a hog memory a mysql database would be far better

 

Scott.

Link to comment
Share on other sites

there is a php function for searching arrays array should be listed there

but i would go with mysql no questions are you sure you don't want the ability to add more pages?

and a array with 10000 strings 10 characters long would be 97kb alone in the file it would slow do the page a hog memory a mysql database would be far better

 

Scott.

 

Alright thanks I wanted to avoid having to learn sql (with all the security concerns) if possible but I guess it's not practical :/

 

Cheers.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.