![]() |
#1
|
||||
|
||||
![]()
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:
__________________
![]() "I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#2
|
||||
|
||||
![]()
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:
__________________
![]() Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#3
|
||||
|
||||
![]()
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: )
__________________
![]() "I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#4
|
||||
|
||||
![]()
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
__________________
![]() Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#5
|
||||
|
||||
![]()
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!
__________________
![]() "I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#6
|
||||
|
||||
![]()
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?
__________________
![]() Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#7
|
||||
|
||||
![]()
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:
__________________
![]() "I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#8
|
||||
|
||||
![]()
Well, change:
PHP Code:
PHP Code:
__________________
![]() Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#9
|
||||
|
||||
![]()
You sir, are amazing 8D
Thank you very much! :D
__________________
![]() "I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#10
|
||||
|
||||
![]()
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?
__________________
![]() Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hall of Famer's PHP Tutorials: Chapter 6 - PHP Arrays | Hall of Famer | Tutorials and Tips | 0 | 03-16-2013 07:14 PM |
My MySQL? | Rozel | Questions and Supports | 6 | 05-01-2011 08:53 AM |
Mysql help? | rickasawr | Questions and Supports | 5 | 04-26-2011 09:31 AM |
MySQL: What to do? | Knyfe | Questions and Supports | 18 | 03-11-2011 12:52 PM |
mySQL help | aroymart | Questions and Supports | 4 | 04-20-2009 12:13 AM |
What's New? |
What's Hot? |
What's Popular? |