What should I do if I only want to echo a piece of data?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.