peter.t Posted October 20, 2009 Share Posted October 20, 2009 Confusing I know. Here's what I've got. I used the Dreamweaver Developer Toolbox in a form that has multiple checkbox results entered into one db column. Id's are entered into this column that join with another table to connect the text to these id's. So the column looks like this: 1,5,7,8. The corresponding text is red, blue, green, yellow. I'm using the str_replace to change the comma to a <BR> so the results read in separate rows. Where I'm drawing a blank is how to show all these results as text. So far I've only been successful showing this: 1 5 7 8 And only the first result as text (red). I'd like the results to look like this: red blue green yellow I'll take any help pointing me in a correct direction. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/178391-loop-to-view-multiple-results-from-one-column/ Share on other sites More sharing options...
peter.t Posted October 21, 2009 Author Share Posted October 21, 2009 OK, I think I know what I need...a for loop in one db column. How to do t his...I'm still searching. Quote Link to comment https://forums.phpfreaks.com/topic/178391-loop-to-view-multiple-results-from-one-column/#findComment-941153 Share on other sites More sharing options...
kickstart Posted October 21, 2009 Share Posted October 21, 2009 Hi Depends how flexible you want it to be. You could use:- $colours = array(1=>'red',5=>'blue',7=>'green',8=>'yellow'); $Fields = explode(',',$row['id']); foreach($Fields as $Field) { echo $colours[$Field]."<br />"; } Trouble is that this requires hard coded lists of colours. It would be better if there was a separate table containing a separate row for each ID for each row from the current table. Then you could just use a JOIN against a table of colours to get them. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/178391-loop-to-view-multiple-results-from-one-column/#findComment-941157 Share on other sites More sharing options...
peter.t Posted October 21, 2009 Author Share Posted October 21, 2009 Thanks! There is a separate table that the values do correspond to. And that's definitely way I'd like to go. This is the column I'm pulling the values from $row_rsKSA['knowledge_ksa'] Here's the equivalent of what I've got: Table 1 = id, color Table 2 = id, color_id The color_id has the multiple values (1,5,7) Quote Link to comment https://forums.phpfreaks.com/topic/178391-loop-to-view-multiple-results-from-one-column/#findComment-941166 Share on other sites More sharing options...
kickstart Posted October 21, 2009 Share Posted October 21, 2009 Hi You really need to split up the field that has multiple values onto a seperate table with one row per value. Eg, while you have something like:- Table1 Id - Name - ColourId 1 - Fred - 1,2,3,4,5 2 - Burt - 2,4,6 What you want is something like:- Table1 Id - Name 1 - Fred 2 - Burt Table2 Id - Table1Id - ColourId 1 - 1 - 1 2 - 1 - 2 3 - 1 - 3 4 - 1 - 4 5 - 1 - 5 6 - 2 - 2 7 - 2 - 4 8 - 2 - 6 While it is possible to do a join against the various values from the comma seperated column, the code to do it is going to be dog slow and isn't particularly friendly for anyone who has to modify it in the future. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/178391-loop-to-view-multiple-results-from-one-column/#findComment-941177 Share on other sites More sharing options...
peter.t Posted October 21, 2009 Author Share Posted October 21, 2009 I gotcha. Makes sense and does seem less painful in the long run. I think I was just trying to combine too many processes into one. I liked the use of the comma-separated checkbox and wanted to run with it. Thanks for the help Keith! Quote Link to comment https://forums.phpfreaks.com/topic/178391-loop-to-view-multiple-results-from-one-column/#findComment-941189 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.