Code Monkey home page Code Monkey logo

Comments (2)

sleiman avatar sleiman commented on August 13, 2024

Hi @peachp thank you for reaching out and for the the feedback! :)

You can use getContent() in order to retrieve a single record using the Record ID.
You just have to specify the 'recId' after the table name (tableName/recId).
This will return a single record, you won't need to loop through the records to retrieve the content.

Here's an example:

$request = $airtable->getContent( 'Tracks/recsJX1bry74HaGBh' );
$response = $request->getResponse();
echo $response->id;

I just did a simple benchmark test for each way. Using a table with less than 500 records, the results were very similar between the two. With a larger set of records, it was much faster to use the Record ID to retrieve your single record.

I hope this helps!

from airtable-php.

peachp avatar peachp commented on August 13, 2024

Hi. Thanks for the tip! Yes, it does help even if it won't be much faster, it is still cleaner compared to doing something like:

$params = array(
                "filterByFormula" => "AND( RECORD_ID() = '$rec_id' )",
                "maxRecords" => 1,
                "pageSize" => 1
);

Thanks again and keep up the good work!

Btw, one of the projects I use your code in is a bespoke theme for the Grav CMS, which will allow to use Airtable as backend / DB for the website. Static pages like Homepage or Contact will be still created in Grav, but repeating, semi-dynamic content such as let's say Portfolio will be managed in Airtable, because it is more comfortable, and in our case we also use the same data for backend order processing. Of course it cannot replace a proper MySQL or similar, but for websites which don't have a lot of visitors and the content doesn't change that often, it's a good GUI / DB combination.

from airtable-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.