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 and
on and
on 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,

Shawn McKenzie schrieb:

On 05/10/2011 03:16 PM, Benedikt Voigt wrote:
I'am very new to PHP, so please any comment is welcome.

I want to write a function in PHP, which takes X arguments and outputs a
The functioning of this function should be stored in a db (mydb? or
better alternatives?)
The function would look up the result in the db based on the X arguments.

But how can I store X arguments and the corresponding output value?
If I limit the X arguments to a specific number like N=10, then I could
create N=10 +1 columns in a table.
But how should I do it if I don't want to limit myself to a fix number?

Thanks for any comment!
Two ways that come to mind:

1. If you don't need to search, join, etc. on any of the arguments in
the DB (*and never will need to*), then serialize the array and store it
in one column and the result in another.

2. Use two tables:

id          result
1           50
2           99

id          results_id          argument
1           1                   800
2           1                   999
3           1                   3.14

Then you just join on arguments.results_id in your query.

If you actually need to store the argument name then just add another
column called variable and change the argument column's name to value.

id          results_id          variable          value

Benedikt Voigt

Tucholskystrasse 33
10117 Berlin
Mobile: 0049/1775902210

25 Carter House
Brune Street
E1 7NN London
Mobile: 0044 7800744839

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to