1

A few day back i had ask a question about Auto generated sequence number staring from 001 .. and which was done.. but suddenly the request from client is change and he want something as below :

test.php?trans_no=3&pid=111&autoid=3 

test.php?trans_no=4&pid=112&autoid=5

as pass parameter is autoid=3 hence 001,002,003 sequence number should be generator with each next ADD button click ( means after clicking ADD button 001 should be store in my table and on next add button fire 002 and so on ).

autoid=5 hence 001,002,003,004,005 sequence number should be generator with each next ADD button click ( means after clicking ADD button 001 should be store in my table and on next add button fire 002 and so on ). llly all other ..

hence my main product id wil be as : 111-001 , 111-002 , 111-003 && 112-001,112-002,112-003,112-004,112-005 and so on and on as per pass parameter ( query string)

Please not its only ex of 3 , 5 number can be anything it can be autoid=200 or autoid=1 or autoid=50 etc..

Community
  • 1
  • 1
  • Although it's a little unclear what you're asking, I think you're confusing data storage and data display. – Strawberry Dec 02 '13 at 10:08
  • no strawberry - this is my client requirement –  Dec 02 '13 at 10:09
  • No. I don't think so. Your client wants to see 001,002,etc. I doubt that they care what's actually stored in the data base. – Strawberry Dec 02 '13 at 10:10
  • what please tell me what you didn't understand .. as clearly mention i need auto generated sequence number on base of parameter pass for "autoid=3 .." –  Dec 02 '13 at 10:10
  • they want to see 001 ,002 .. but it should be as per parameter value hence each link have 001 , 002 but it will depend on value which is pass with "autoid" hence that much auto number will be generated with each click of add button and i want to store that in my table .. as which will be used for reference of product NUmber and barcode –  Dec 02 '13 at 10:13
  • strawberry u there? ,.. any solution –  Dec 02 '13 at 10:18
  • If the autoid = 3, what happens the 4th time the 'Add' button is pressed? – Strawberry Dec 02 '13 at 10:19
  • good question strawbbery .. as autoid=3 means 003 is set in table then automatically add button should be removed or hide etc ... with some message .. –  Dec 02 '13 at 10:23
  • OK. I don't really see the problem. Either you're going to store the product code (112,111,etc) along with the max sequence value or you're going to store the product code alongside EVERY possible sequence value. This number doesn't have to be generated by MySQL. Your application level code can construct the number. – Strawberry Dec 02 '13 at 10:32
  • productcode is what my 2 parameter (pid=111 and pid=112) which is already in table ..auto sequence is my sub product code hence it will be 111-001 , 112-001 ( which i will do with join query ) –  Dec 02 '13 at 10:35
  • " Your application level code can construct the number. " thats what i need :( –  Dec 02 '13 at 10:36

1 Answers1

0

Well, crudely (very crudely)...

<?php

if(isset($_GET['item'])){
$item = $_GET['item'];
$max_val = $_GET['max_val'];

for($i=1;$i<=$max_val;$i++){
echo $item."-".$i."<br>\n";

}
}else {

?>

<form name = 'my_form' method='get' action='so_temp2.php'>

<input name = 'item' type = textbox/>

<select name = 'max_val'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>

<input type=submit />

</form>

<?

}
?>

or... if you just want to construct a simple insert...

<?php

if(isset($_GET['item'])){
$item = $_GET['item'];
$max_val = $_GET['max_val'];

echo "INSERT INTO my_table (item,max_val) VALUES ($item,$max_val);";

}else {

?>

<form name = 'my_form' method='get' action='so_temp2.php'>

<input name = 'item' type = textbox/>

<select name = 'max_val'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>

<input type=submit />

</form>

<?

}
?>
Strawberry
  • 33,750
  • 13
  • 40
  • 57
  • query for insert :) , that to with auto generated sequence number as per pass parameter value –  Dec 02 '13 at 11:02
  • dude i need auto generated sequence number after each add button is fire not in loop , first add button is fire then i will get 001 and i will store this in my table coloumn of "autoid" , second time add button is fire then auto 002 number is generated and which again is store in table ..and so on –  Dec 02 '13 at 12:37
  • dude, your problem is one of design. I'm not designing it for you. EITHER the sequence id is generated in PHP, in which case adapt the example I've provided, OR it's generated in MySQL, in which case consider using a MyISAM engine which allows an auto_incremented id to be used as part of a compound PK. – Strawberry Dec 02 '13 at 13:51