glennn.php Posted June 23, 2010 Share Posted June 23, 2010 ok, i'm having trouble wrapping my mind around this little hurdle: having this: $option_1 = $row['option_1']; $option_2 = $row['option_2']; [...] $option_78 = $row['option_78']; where ANY of $option_x would contain: switch ($options) { case "option_19000" : $option = "aaa"; break; case "option_19001" : $option = "bbb"; break; [...] case "[b]option_19176[/b]" : $option = "176xxx"; break; } and i have this, which gets me what i want from the database: for ($i=1;$i<76;++$i) { if (${'option_'.$i} != '') $pagetext .= ${'option_'.$i} . "<br>\n"; } i can't figure out how to then apply my switch when $pagetext contains, say "option_19001"... i'd appreciate any help someone can offer. GN Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/ Share on other sites More sharing options...
trq Posted June 23, 2010 Share Posted June 23, 2010 Your use of variable variables is making this look more complicated than likely need be. I'm really not sure what your asking. And why the need for variable variables? Arrays are for more efficient and much easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076056 Share on other sites More sharing options...
glennn.php Posted June 23, 2010 Author Share Posted June 23, 2010 agreed, i'm sure i've made it more complicated than needed - my client supplied me with spreadsheets of these options ... let me try to draw up a little schema: FIELDS | option_1 | option_2 | option_3 | VALUES | option_19015 | option_19001 | option_19065 | VALUES | option_19022 | | option_19043 | Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076059 Share on other sites More sharing options...
glennn.php Posted June 23, 2010 Author Share Posted June 23, 2010 the thing is, there are 280+ RECORDS, with 75+ options_X, with 176 options_values... SOME which will be empty, so i did the iteration to skip the empty ones... Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076062 Share on other sites More sharing options...
trq Posted June 23, 2010 Share Posted June 23, 2010 Sorry, but I still don't understand your question / issue at all. Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076069 Share on other sites More sharing options...
glennn.php Posted June 23, 2010 Author Share Posted June 23, 2010 ok, gimme a sec... i'll attach some code. Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076070 Share on other sites More sharing options...
glennn.php Posted June 23, 2010 Author Share Posted June 23, 2010 heck, i'll write it in english/sql... select * from table where id = 1; i'll get o _1 thru o_76 THAT CONTAIN A VALUE if ($o_1 == "option_19001") { pagetext .= "aaa'; } elseif ($o_1 == "option_19002") { // $option_19001 thru $option_19176 pagetext .= "bbb"; } if ($o_2 == "option_19001") { pagetext .= "aaa'; } elseif ($o_2 == "option_19002") { // $option_19001 thru $option_19176 pagetext .= "bbb"; } // $o_1 thru $o_76 Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076075 Share on other sites More sharing options...
glennn.php Posted June 23, 2010 Author Share Posted June 23, 2010 i'm very sorry. i don't know why this is hard to understand... i have 76 variables i retrieve from the database: $o_1 = $row['option_1']; $o_76 = $row['option_76']; each variable in turn contains 1 of 175 values each of which refer to another (longer) value. my client did this in a spreadsheet. option_19001 thru option_19176 so for each $o_xx (x 76) I have "option_xxxxx" which represents a value contained in a long switch... am i being daft? Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076116 Share on other sites More sharing options...
trq Posted June 24, 2010 Share Posted June 24, 2010 so for each $o_xx (x 76) I have "option_xxxxx" which represents a value contained in a long switch... am i being daft? Not daft, but you haven't really explained what you want to do with this data. Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076341 Share on other sites More sharing options...
glennn.php Posted June 24, 2010 Author Share Posted June 24, 2010 $if ($o_1 == "option_19001") { $pagetext .= "aaa'; } elseif ($o_1 == "option_19002") { // $option_19001 thru $option_19176 $pagetext .= "bbb"; etc... } if ($o_2 == "option_19001") { $pagetext .= "aaa'; } elseif ($o_2 == "option_19002") { // $option_19001 thru $option_19176 $pagetext .= "bbb"; etc... } // $o_1 thru $o_76 echo $pagetext; Quote Link to comment https://forums.phpfreaks.com/topic/205631-couple-of-different-iterations-i-need-to-merge-i-think/#findComment-1076578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.