![]() |
MySQL + Arrays?
Right, so having an issue here >.> I have two arrays I'm trying to make (one of which is working fine :3) but the second one seems to be running into an issue with the fact I'm trying to call an array from a MySQL cell.
So basically this MySQL cell has the phrase "3,4,5,6" (no quotes). It is set to a variable $adoptid which I'm trying to put in an array. Problem is it treats the whole variable as an array. So instead of using '3', '4', '5', and '6' as variables in the array it treats "3,4,5,6" as a variable in the array. (if that just made sense...) Does anyone know a way I can put values into a MySQL cell and then pick one randomly from an array? Trying to do something like: PHP Code:
|
Well you cannot send an array or object directly into mysql database, but there is a way to do the trick. Lets assume you have an array as below, the script will be able to perform magic for you:
PHP Code:
To retrieve this data from your mysql table, use the explode function: PHP Code:
|
Ah thank you! :D That worked perfectly!
And I do have a random feature right now, but it seems to be picking the lower numbers quite more often than it should D: PHP Code:
(then I ran the loop again and 5/6 didn't appear at all D: ) |
Well the problem is that you are choosing two random values from the array input[], while the function array_rand() automatically sort the two generated values. The possible combinations from the array $rand_keys[] is:
PHP Code:
There are many ways to resolve this glitch. If you insist on working with array_rand() function, Id recommend you use PHP shuffle which destroys the orders in an array and randomize it. The instruction on how to use shuffle can be found from php's official site: http://php.net/manual/en/function.shuffle.php |
Hm, well the thing is if I try to get only one output it just doesn't output anything D: So I have to leave the two there for it to work at all D: But I will check out that link you gave :3 Thank you!
|
umm what do you mean by that? It is supposed to work however many output you use. Mind showing me your entire script so I will see what is wrong with it?
|
What I mean is if I change
PHP Code:
PHP Code:
And this is my code: (it's for the Altara site so it's not Mysidia code at all >.<" I hope it's alright to ask for help with that here o-o) PHP Code:
|
Well, change:
PHP Code:
PHP Code:
|
You sir, are amazing 8D
Thank you very much! :D |
You are very welcome, glad I can be of any help. It seems that you are using object-oriented codes in your script, are you comfortable with classes/objects already?
|
All times are GMT -5. The time now is 09:17 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.