Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:43:02+00:00 2026-06-17T09:43:02+00:00

I have a table of serial keys +—-+———————+——+ | id | product_key | used

  • 0

I have a table of serial keys

+----+---------------------+------+
| id | product_key         | used |
+----+---------------------+------+
|  1 | 3C45-GH76-9V74-HLKJ |    1 |
|  2 | REDF-6KI9-00IU-4867 |    0 |
|  3 | 1111-1111-1111-1111 |    0 |
|  4 | 2222-2222-2222-2222 |    0 |
|  5 | 3333-3333-3333-3333 |    0 |
+----+---------------------+------+

I would like to get one row record that used=0 using zend framework. Then change to used=1 if that product_key had select.

I am confuse using Zend.

I think it’s something like that, but how to assign “1” into used if that product key had been select?

$productKey = $this->_helper->model('ProductKeys')->fetchOne('SELECT * from product_keys WHERE used=0 LIMIT 1');
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:43:03+00:00Added an answer on June 17, 2026 at 9:43 am

    There does not appear a way to do it in a single simple query. Also, fetchOne only gets the first column of the first record. That helper would return just the ID, and not the product_key.

    Option 1:
    Modify your ProductKeys model to get the key and set it as used:

    class My_Model_ProductKeys extends Zend_Db_Table_Abstract
    ...
    function getKeyAndMarkUsed()
    {
      $select = $this->select();
      $select->where('used=?',1)->limit(1)->order('ID');
      $keyRow = $this->fetchRow();
      if ($keyRow){
        $this->update(array('used'=>1),'id='.$keyRow->ID);
        return $keyRow->id;
      }
      else{
        //no keys left! what to do??? Create a new key?
        throw new Exception('No keys left!');
      }
    }
    

    Then you would just:

    $productKey = $this->_helper->model('ProductKeys')->getKeyAndMarkUsed();
    

    Option 2:
    Make a database procedure to do the above functionality and call that instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a sql server table of licence keys/serial numbers. Table structure is something
I have a table that looks like this: CREATE TABLE foobar ( id SERIAL
I have a table in my postgresql 8.4 database like this: id(serial), event_type_id(id, foreign
Say I have a table, created as follows: CREATE TABLE test_table (id serial, unique_id
I have a table that tracks serial numbers and the number of licenses associated
I have a table: CREATE TABLE cell ( cellpk serial NOT NULL, cellname character
I have a table like this - cdr_pkey as serial, calldate as timestamp, src
I have created a table in postgresql 9 create table stillbirth(id serial primary key,
I have a table: CREATE TABLE field_data.soil_samples ( pgid SERIAL NOT NULL, sample_id text,
I have a table with a SERIAL primary key, and also an ltree column,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.