Right, i thought i could do it, but my head hurts currently.. so..
Any advice?
basically, if i have an array setup like
array('users' => array('username' => 'value','password','email'));
I need to have it so that It gets built into a mysql query as so:
SELECT * FROM users WHERE username = 'value' AND password = 'value' AND email = 'value'";
for example (written badly, purely for ease of use)
But..
Also, i need to know, is tehre a way to use 1 query to run multiple table checks? or will I need to run a query per array key? (like if the array was setup to have 'users' and 'login' or something?
multidimensional array building a query
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
multidimensional array building a query
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: multidimensional array building a query
foreach ($array[1] as $column => $value){ $conditions[] = "`{$column} = '{$value}'"; } $sql = 'SELECT `things` FROM `' . $array[0] . '` WHERE ' . implode(" AND ", $conditions);Something like this would do it I think...
And I have no idea what you mean by the second thing.
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: multidimensional array building a query
why do you start with array[1] ?
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: multidimensional array building a query
Because you didbowersbros wrote:why do you start with array[1] ?
is element 0 not the table name ?array('users' => array('username' => 'value','password','email'));
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: multidimensional array building a query
elemt 0 is the table name, but (but the key is the table name, not the value) then the value of 0 is the multi array, where the key to them are the field names and the values to those respectively are the values to check for.
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: multidimensional array building a query
Oh I see, sorry I misread.
It might be better not to structure it like this, it's making it too awkward to work with
It might be better not to structure it like this, it's making it too awkward to work with
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: multidimensional array building a query
Okay, so we'll have to do it as Normal array or static string. got it ;D
/edit. kind of makes that array_is_multi function useless now though?
/edit. kind of makes that array_is_multi function useless now though?
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: multidimensional array building a query
Well it might be useful for something elsebowersbros wrote:/edit. kind of makes that array_is_multi function useless now though?
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: multidimensional array building a query
used it anyway, so if one is submitted it will failjacek wrote:Well it might be useful for something elsebowersbros wrote:/edit. kind of makes that array_is_multi function useless now though?
and added a little //maybe one day comment
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9