I have this mysql query (using pdo) :
SELECT DISTINCT CONCAT (nompropre, ' ', Auteur, ' de ', localite) AS auteur FROM Actes ORDER BY nompropre
It is used to create a select menu. Trying to analyse the input received from a form (select) :
<option value=" abbé de Val-Saint-Lambert"> abbé de Val-Saint-Lambert</option>
<option value=" abbé de Waulsort"> abbé de Waulsort</option>
<option value="Arnoul III comte de Looz et Chiny">Arnoul III comte de Looz et Chiny</option>
<option value="Arnoul III seigneur de Looz et Chiny">Arnoul III seigneur de Looz et Chiny</option>
<option value="Jean de Wasnes chevalier de ">Jean de Wasnes chevalier de </option>
<option value="Adam évêque de Morinie">Adam évêque de Morinie</option>
Then I do this :
$parts = explode(' ', $_GET['nompropre']);
What I need to do is rebuild the mysql fields that I first concatenated so I can end up with such a query (corresponding to last select in example above) :
SELECT * FROM Actes, Bibliographie WHERE id = idBiblio AND nompropre = 'Adam' and Auteur = 'évêque' AND localite = 'Morinie';
For this, I could isolate a string (abbé || comte || seigneur) and make this Auteur (for the purpose of the mysql query for get results)
Everything that is before that string should become nompropre
the word "de" if it exists after that string should be removed and
everything after the word "de" (removed) should become localite for the mysql query.
maybe a preg_match and preg_replace would do the job.
DISTINCT, you only need to get all records (that are unique) of the author table. 2) concatenation is not a job for mysql but for php. Once you have separated fields (nompropre, localite...) for each records you can easily concatenate them the way you want with php.