PHPsites Posted September 10, 2007 Share Posted September 10, 2007 Hello. Was hoping someone can help with the following.... Background: Have a table with a primary key and then numeric columns (ex. 1-30). Every record has data in at least the first column but may have up to 30 columns of data. Data in each column is unique. Once the proper row is found, i need to test for the existence of a value within any of the 30 numeric columns. 1) What is the fastest way to accomplish this? Currently read row data into an array and use a loop to test each element's equality to the value. Slow. 2) Could someone recommend a better way to design the table? Appreciate any help anyone can provide. Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/68758-help-with-table-design-and-locating-data/ Share on other sites More sharing options...
PHPsites Posted September 10, 2007 Author Share Posted September 10, 2007 OK, so I discovered the in_array function. That answers question 1. Anyone have any better ways to design the table to avoid uneven columns? Really not a problem anymore but I am definitely interested in hearing others' responses / ideas. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/68758-help-with-table-design-and-locating-data/#findComment-345635 Share on other sites More sharing options...
Barand Posted September 11, 2007 Share Posted September 11, 2007 Instead of a table with the 30 cols (some of them empty) have a table with id, value in each row. With just as many rows as there are values. instead of [pre] id | val1 | val2 | val3 | ... | val30 | ----+------+------+------+-----+-------+ 123 | 10 | 11 | 15 | | | [/pre] have [pre] id | val | ----+-----+ 123 | 10 | 123 | 11 | 123 | 15 |[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/68758-help-with-table-design-and-locating-data/#findComment-345698 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.