Welcome Guest, Not a member yet? Register   Sign In
Set autoincrement value for each value in row -- php
#1

[eluser]masentinel900[/eluser]
Hello guys!!

Really I'm a bit confused about how can I set this requirement.

I need to set a row in my table like serial type, But I need to set before some requirements. such as that for each value in the row start the serial counter.

[For example]

ROW-1 -- ROW-2
1 1
1 2
1 3
1 4
1 5
1 6
2 1
2 2
1 7
1 8
2 3
2 4


This example means that for each value in the ROW-1 start a counter from 1 until infinite.
Really now I don't know how can I get it.
Please if do you have an idea, or maybe you has made this before. let me know.
#2

[eluser]Uresh Patel[/eluser]
HI,

You need to put two "for" loop for getting this solution.

E.G:
Code:
$AryCounter = array();
$k =0;
for($i=0;$i<10;$i++){
        
           for($j=0;$j<5;$j++){
      $AryCounter[$i] = $k++;    
    echo $i."=>>>".$AryCounter[$i]."</br>";
           }
     $k =0 ;
}  

print_r($AryCounter);
I have made sample example...you can manipulate and do final touchup
#3

[eluser]masentinel900[/eluser]
Friend many thanks by your response, But I believe that doesn't works for me. I going to expose of the better way my problem.

[DB]
CREATE TABLE "processOrder"
(
"idOrderProcess" serial NOT NULL,
idproceso integer NOT NULL,
"conseFunction" integer NOT NULL,
idfuncion integer NOT NULL,
creadopor integer NOT NULL,
fechacreacion date NOT NULL,
CONSTRAINT "pkOrderProcess" PRIMARY KEY ("idOrderProcess"),
CONSTRAINT "fKFunction" FOREIGN KEY (idfuncion)
REFERENCES funciones (idfuncion) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT "fKProcess" FOREIGN KEY (idproceso)
REFERENCES procesos (idproceso) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT "fKUser" FOREIGN KEY (creadopor)
REFERENCES usuario (idusuario) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)

[Controller]
Code:
function postFunctionByProcess(){
  $insertprocessOrder = $this->input->post('insertprocessOrder');
  $session_data = $this->session->userdata('logged_in');
  $SprocessOrder = $this->input->post('processOrder');
  $ordFunction = $this->input->post('ordFunction');
  $ordProcess = $this->input->post('ordProcess');
  date_default_timezone_set('UTC');
  $this->load->helper('date');
  $datestring = "%Y-%m-%d";
  if($ordFunction || $ordProcess == 0){
   echo "Seleccione 2 opciones antes de enviar";
  }else{
    $data = array(
    'idproceso' => $ordProcess,
    'conseFunction' => $conseFunction,
    'idfuncion' => $ordFunction,
    'creadopor' => $data['idusuario'] = $session_data['idusuario'],
    'fechacreacion' =>mdate($datestring)
    );
   }}

[Jquery]
Code:
function postFunctOrder(){
$("#five form").submit(function(evnt){
evnt.preventDefault()
$.post('functionPortal/postFunctionByProcess',{'ordProcess':$(this).children('select[name="ordProcess"]').val(), 'ordFunction':$(this).children('select[name="ordFunction"]').val()},function(data){
  $("#data").html(data)
  })
})
}


[HTML]
Code:
<div id="five" >
&lt;form method="post"&gt;
<fieldset>Select Process</fieldset>
<select class="selecInput" name="ordProcess">
<option disabled="disabled" selected="selected" value="0">Select Process</option>
    &lt;?php foreach($selectProcess->result_array() as $row):?&gt;
    <option value="&lt;?php echo $row['idproceso'];?&gt;">&lt;?php echo $row['nombreProceso'];?&gt;</option>
    &lt;?php endforeach;?&gt;
</select>
<fieldset>Select Function</fieldset>
<select class="selecInput" name="ordFunction">
<option disabled="disabled" selected="selected" value="0">Select Function</option>
    &lt;?php foreach($ViewFunciones->result_array() as $row):?&gt;
    <option value="&lt;?php echo $row['idfuncion'];?&gt;">&lt;?php echo $row['descripcioncorta'];?&gt;</option>
    &lt;?php endforeach;?&gt;
</select><br />
&lt;input type="submit" class="button-style" value="Enviar" /&gt;
<div id="data"></div>
&lt;/form&gt;
</div>
#4

[eluser]TheFuzzy0ne[/eluser]
Sorry, I have absolutely no idea what it is you're trying to do. What is it you're trying to do? Can you explain what your app does, please?
#5

[eluser]obiron2[/eluser]
I think his database table has a compound primary key of Row1/Row2 (bad field labelling!)
Think of them as OrderNumber/LineNumber

When you add a record to the database for a particular order number the line number should be one higher that the highest line number on that order.

To do this you will have to poll the database

$query = "SELECT max(lineno) as 'LineNo' from myTable where orderref = $orderRef"

$qUpdate "INSERT INTO myTable (OrderRef,LineNo) VALUES ($orderRef,($query->row()->lineno+1))"

You run the risk of concurrency issues if more than one browser window could update the order at the same time so you would need to look at some sort of record locking or pre-creating the row and then updating it.





Theme © iAndrew 2016 - Forum software by © MyBB