Najdorf Posted February 14, 2009 Share Posted February 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145184-solved-php-declared-array-vs-mysql-calls/ Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 You can use the in_array function for this, but if contains as many IDs as you say then it would be better to store all the IDs in a database and check if it's there using SQL. Quote Link to comment https://forums.phpfreaks.com/topic/145184-solved-php-declared-array-vs-mysql-calls/#findComment-762022 Share on other sites More sharing options...
ratcateme Posted February 14, 2009 Share Posted February 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145184-solved-php-declared-array-vs-mysql-calls/#findComment-762024 Share on other sites More sharing options...
Najdorf Posted February 14, 2009 Author Share Posted February 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/145184-solved-php-declared-array-vs-mysql-calls/#findComment-762036 Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 Checking against a predefined array is only practical as long as it is small and relatively static. If you wish to become a programmer then SQL is a highly useful tool so you would want to learn it anyway. Quote Link to comment https://forums.phpfreaks.com/topic/145184-solved-php-declared-array-vs-mysql-calls/#findComment-762038 Share on other sites More sharing options...
ratcateme Posted February 14, 2009 Share Posted February 14, 2009 And SQL is also fairly simple for basic projects check out tizag.com for some tutorials it also covers basic injection protection normally all u need is mysql_real_escape_string it works wounders with most applications Scott. Quote Link to comment https://forums.phpfreaks.com/topic/145184-solved-php-declared-array-vs-mysql-calls/#findComment-762040 Share on other sites More sharing options...
Najdorf Posted February 14, 2009 Author Share Posted February 14, 2009 Cool, thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/145184-solved-php-declared-array-vs-mysql-calls/#findComment-762042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.