There is a lot of data in the year field so that we can echo a lot of data. This data is the same, so I only want to echo a piece of data. What should I do? {Code...} There is a lot of data in the year field so that we can echo a lot of data. This data is the same, so what should I do if I only want to echo a piece of data?
$ Res = $ stmt-> fetchall (PDO: FETCH_ASSOC); foreach ($ res as $ v) {echo $ v ['Year'];}
Reply content:
There is a lot of data in the year field so that we can echo a lot of data. This data is the same, so I only want to echo a piece of data. What should I do?
$ Res = $ stmt-> fetchall (PDO: FETCH_ASSOC); foreach ($ res as $ v) {echo $ v ['Year'];}
First, if you want to query all and output a year, then $ v = current ($ res); echo $ v ['Year'];
Second, if you want to find an output, add limit 1 to the query statement.
Third, if you have multiple year records, and there are duplicates in them, var_dump (array_unique (array_column ($ res, 'Year '));)
1. If you only get one entry, do not use fetchAll or fetch.
$ Res = $ stmt-> fetch (PDO: FETCH_ASSOC );
2. Add limit 1 to the original SQL statement.