Results 1 to 3 of 3

Thread: basic module with database content

  1. #1
    New user
    Join Date
    07-05-09.
    Posts
    27

    Default basic module with database content

    Hello guys,

    I'm trying to develop my first TL extension, I've been able to create an extension that lists products retrieved from a database table, so I suppose the hardest part is done

    the module simply executes this query SELECT * FROM products ORDER BY name LIMIT 5, now I'd like to be able to set dynamic conditions for this module, so that I can edit the query to accept a variable, example SELECT * FROM products WHERE name like '%".$somename."%' ORDER BY name LIMIT 5

    I should be able to set a different $somename variable value for every page: where can I store this value so that I can use it in my query? what if I wanted to use more than a single value?

    any suggestion is appreciated, I know it may sound very basic but....

  2. #2
    User
    Join Date
    08-07-09.
    Location
    Kent, United Kingdom
    Posts
    92

    Default Re: basic module with database content

    Hi JTO,
    Use the following syntax:
    $this->Database->prepare('SELECT * FROM products WHERE name like "%?%" ORDER BY name LIMIT 5')->execute($variable);

    Where is the variable value being retrieved from?
    Input? Post? Or something else?

    If you want to match more than one condition then delve deep into some Mysql string pattern matching, I'd advise very strongly against doing multiple database lookups.

  3. #3
    New user
    Join Date
    07-05-09.
    Posts
    27

    Default Re: basic module with database content

    thank you very much, that's exactly what I was looking for, or at least part of it
    >>>Where is the variable value being retrieved from?
    I'd like to make it possible to set the variable content in every page or content item

    let's assume I put this extension at the end of every page, and I'd like to retrieve records for 'blue widgets' in a page, 'red widgets' in the other and so on

    I would basically need some room to store its content in every page....any hints?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •