Jump to content

Help with table design and locating data


PHPsites

Recommended Posts

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.