MySQL: Searching on variable field names and numbers

Discussion in 'MySQL' started by Cobnut, Mar 6, 2008.

  1. #1
    My db has tables dedicated to storing customer data that are created when a new 'store' is created. There are a number of standard fields in these tables but each has a variable number of 'additional data' fields that are defined by the user at the time of creation. Each of these fields needs to be searched on demand.

    How can I build a query that looks for a searched term in each of these fields without knowing in advance how many there are (if there are any at all - some don't have any add-ons)? I can do it in PHP by sending the function a list of the additional field names and building the query before submission but that strikes me as clumsy. Is there a way to do it directly in MySQL?

    So, for example, how can I write a query that'll look for a specified term in each of the 'f' fields in the example tables below (all these fields begin 'f')?

    id,blah1,blah2,date,f20,f21
    id,blah1,blah2,date,f45,f46,f47,f48
    id,blah1,blah2,date

    Any help appreciated.

    Jon
     
    Cobnut, Mar 6, 2008 IP