> Date: Wed, 11 May 2011 22:15:21 +0200
> From: benedikt.vo...@web.de
> To: nos...@mckenzies.net
> CC: firstname.lastname@example.org
> Subject: Re: [PHP] Re: Storing indefinite arrays in database
> Thanks Shawn,
> yes, your second idea works for me. The first one not, as I need to
> search and join on it.
> To continue your second idea with your example:
> id results_id variable value
> 1 1 1 800
> 2 1 2 999
> 3 1 3 3.14
> id result
> 1 50
> 2 99
> The Arguments and Results table would be filled dynamically by user content.
> In order to run a function, I have to do N times a join, whereas N is the
> number of arguments:
> select result
> from Results join Arguments as A1 join Arguments as A2 join Arguments as A3
> on Results.id=A1.results_id and
> on Results.id=A2.results_id and
> on Results.id=A3.results_id and
> A1.variable=1 and A1.value=800 and
> A2.variable=2 and A2.value=999 and
> A3.variable=3 and A3.value=3.14 and
> A1.results_id=Results.results_id and
> A2.results_id=Results.results_id and
> Theoretically this works, but how good will be the performance if there are
> Thousands of entries?
> Anyway, I will try out.
> Thanks again,
Firstly, as this is my first post to this list I apologize for any etiquette
I would like to suggest to you a different approach, which would be more
First, you would have a table which stores the number of arguments of a certain
entry, something like
You would store the num_of_arg entry in a PHP variable, say $num.
Then you would proceed to use
"CREATE TABLE IF NOT EXISTS \'entries_".$num."\' ...some more code..."
to create a table which can store precisely $num arguments per record.
Then you add it to that table using standard MySQL.
Effectively this groups all records into tables according to $num.
The only thing here is that you probably need to call the database two times:
- first to get num_of_arg to be able to call onto the right table
- second to get the data
But as the number of arguments would go into the thousands, no huge join would
Only thing is, that you would have very wide tables (I don't know how wide
MySQL can go).
Creating tables on-the-fly as necessary seems to be something you could
but again I stress that I don't know performance details. There might be
So far for my 2c. Hopefully, it is of some help.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php