Bump up variables to replace empty vals, variable variables?
Posted: Sun May 16, 2010 3:46 pm
Hi everyone
This has been driving me nuts over the weekend, trying to find the best way to do this.
I need to take 3 telephone, 3 fax numbers (and 3 emails and websites also) and store them in a MySQL table.
The variables are numbered tel1, tel2, tel3, fax1, fax2, fax3 and if one is empty, then bump the others up in its place.
So if tel1 is empty then tel2 and tel3 each get bumped up one place.
And if tel1 has a value, tel2 is empty, then move tel3 to tel2 etc.
... And the same for the fax nos.
Can anyone think of a better way to do this other than nesting a whole bunch of ifs...elseifs?
We might want to add more values in the future so normally I would do this with related tables in our DB but we're going to be building some queries with a plenty of joins so I'd like to keep them in the same table.
Just wondering if anyone can suggest a quick/short way of doing this?
Cheers, B
This has been driving me nuts over the weekend, trying to find the best way to do this.
I need to take 3 telephone, 3 fax numbers (and 3 emails and websites also) and store them in a MySQL table.
The variables are numbered tel1, tel2, tel3, fax1, fax2, fax3 and if one is empty, then bump the others up in its place.
So if tel1 is empty then tel2 and tel3 each get bumped up one place.
And if tel1 has a value, tel2 is empty, then move tel3 to tel2 etc.
... And the same for the fax nos.
Can anyone think of a better way to do this other than nesting a whole bunch of ifs...elseifs?
We might want to add more values in the future so normally I would do this with related tables in our DB but we're going to be building some queries with a plenty of joins so I'd like to keep them in the same table.
Just wondering if anyone can suggest a quick/short way of doing this?
Cheers, B