Sql query issue in php repository

In a simple search form, if we search 1232, we get a word that is stored as in this table, we get cat from db using a simple query select 'word' from 'dawat' where counting ='%$term%' samely 2454 for dogs etc. Form Code:

 <form action="upload.php" method="get" > <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="submit" name="submit"> </form> 

and tables in db:

 counting word 1232 cat 2454 dog 4844 fish 7785 goat 

Now it works correctly, the problem is that several queries have the same value, as we can store in mysql.Suppose, all are different not. have the same meaning, that is, a cat, so we can normally store as:

 counting word 1232 cat 2454 cat 4844 cat 7785 cat 

Here is how we can create different coloumns for single.Now, the main question is how can I assign all the different ones for cat cating in a single coloumn, for example:

  counting word 1232,2454,4844,7785 cat 5785,4577,9644,6549 dog 
+5
source share
1 answer

Try something like that (edited):

 SELECT GROUP_CONCAT(dawat.counting SEPARATOR ',') AS counting, dawat.word FROM dawat GROUP BY dawat.word; 

in case you can use concatenated values, you can use this version:

 SELECT GROUP_CONCAT(dawat.counting ORDER BY dawat.counting ASC SEPARATOR ',') AS counting, dawat.word FROM dawat GROUP BY dawat.word; 
0
source

Source: https://habr.com/ru/post/1210029/


All Articles