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 7862849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:17:57+00:00 2026-06-02T23:17:57+00:00

i have made a code to generate 11 digit random number and i want

  • 0

i have made a code to generate 11 digit random number and i want to save all number in database

admin_create_epin.ctp(view)

<tr>
   Add E-pin:(No of E-Pin)
   <td><?php echo $this->Form->input('e_pin',array('label'=>false));?></td> 
</tr>

epins_controlller.php

 public function admin_create_epin(){

   $limit = $this->data['Epin']['e_pin'];

   for($i=0;$i<$limit;$i++)
      {
         $random = substr(number_format(time() * rand(),0,'',''),0,11)."<br/>";
         $this->data['Epin']['e_pin'] = $random;

        //pr($this->data); it's show all random number

         $this->Epin->save($this->data);          // i have problem only here it's save only last random number
         $this->Session->setFlash("Epin has been added");
         $this->Redirect(array('action'=>'admin_create_epin')); 
    }   
}

Issue:Code generate all random number but i have problem in my code insert only last random number not all and i want to insert all random number

thanks

  • 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-02T23:17:58+00:00Added an answer on June 2, 2026 at 11:17 pm

    1) You have to move Redirect() outsite the loop.

    2) After the first $this->Epin->save(...) last inserted id is stored in $this->Epin->id and then is used for update records with this id for following iterations. So you will have only one record inserted, and rewritten in the last iteration.

    Reset it before saving:

    for($i=0;$i<$limit;$i++)
      {
         //...
         $this->Epin->id = null; // <- force insert in the next save
         $this->Epin->save($this->data);          // i have problem only here it's save only last random number
         //...
    } 
    

    Also you can try create() method:

    $this->Epin->save($this->Epin->create($this->data));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made this code to open a database(created in SQLite browser) stored in
I have to generate all variations without repetitions made of digits 0 - 9.
I want to generate a random number of 14 positive digits only and I
my question is that I have made multimap.Here is the partial code. if(binary_search(final.begin() ,
I have a problem, and I made this test code to show you my
Greetings, SO. I have some code which I've made attempts at compiling using gcc,
I have made this piece of code that makes a roll hover effect on
I have made a java application and wants to generate log files so whenever
We have a social site, and want to integrate facebook connect to save time
I have implemented a code that generate the infinite sequence given the base case

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.