Jump to content

PHP creating extra table rows with a given value.


TAViX

Recommended Posts

Hello guys. First let me tell you that I'm realy n00b in coding bussiness, my real job involves 3D design not web design, but still I have a very important project and it seems I can only get help by asking YOU people realy nice . :bow:  :bow:

 

So my problem is:...

 

First on the page I have 2 text fields, for example, one with a "Batch Nr.", and another with "Person Nr".

I also want to have a hidden form with a table that will appear only after I've clicked on the subbmit button (CREATE) in my case.

 

And here is the catch. My table has only 1 row created, that's the title row, BUT the next rows (the number of) are needed to be created by the given value in the "Person Nr." text box. In other words, if I have 5 persons imputed, than the table will need to have extra 5 rows.

 

I have drawn a sketch in paint (  :oops: ) to easily understand what I'm asking...:

 

phpcreatetablerowsbyaspun3.gif

 

Then after creatind the rows, I need that the first column to be populated first, with "Batch number", then with a 3 digit nr, from 001 to "Person Nr.", for example 165001.

 

THANK YOU GUYS IN ADVANCE, I kind of known the principle of how to do this, but I need some code, because PHP programing is not my strongest point.

Thank you again.

Link to comment
Share on other sites

Where does the batch numbers and person numbers come from (IE: how are going to compare them, so you know they are valid?) I understand what you are wanting to do, my question relates to once those inputs are passed to the script... How are going to validate them so you know they are valid, (IE, correct format) explain that please.

Link to comment
Share on other sites

Where does the batch numbers and person numbers come from (IE: how are going to compare them, so you know they are valid?) I understand what you are wanting to do, my question relates to once those inputs are passed to the script... How are going to validate them so you know they are valid, (IE, correct format) explain that please.

 

Ah, sorry for not being entirely clear. Those numbers I will imput them from the keyboard.

Ok. I need to create new entries in database(the tables are like the ones in the registration table from the image). But I need in "trainee code" column to have the code formed by the "batch number" and the next increasing value (for exemple if I need to add 5 more persons, they will be displayed in the "trainee code" column).

Anyways the biggest problem is, after I imput those numbers from keyboard, press the CREATE button, to create the extra rows of the table with those values added in the "trainee code" column.

Link to comment
Share on other sites

Ok guys. I've managed to make the script, but can you help me now a little? I need that after inserting the data in the textboxes, press the PREVIEW button, to list the data inputed, and to have 2 choices, INSERT in the database, and BACK to edit the texboxes again. I have a very hard time also to create the script that uploads all the data, after PREVIEW, in my database.

 

mysql_select_db($database_DB_rev00, $DB_rev00);
$query_Batch_in = "SELECT trainee_code, sur_name, given_name, middle_name, nickname FROM passport_info";
$Batch_in = mysql_query($query_Batch_in, $DB_rev00) or die(mysql_error());
$row_Batch_in = mysql_fetch_assoc($Batch_in);
$totalRows_Batch_in = mysql_num_rows($Batch_in);

mysql_select_db($database_DB_rev00, $DB_rev00);
$query_compcode = "SELECT comp_code FROM comp_info";
$compcode = mysql_query($query_compcode, $DB_rev00) or die(mysql_error());
$row_compcode = mysql_fetch_assoc($compcode);
$totalRows_compcode = mysql_num_rows($compcode);
?><html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Batch Member Input</title>
<style type="text/css">
<!--
#title {
position:absolute;
left:150px;
top:82px;
width:742px;
height:154px;
z-index:1;
}
body {
background-repeat: no-repeat;
}
#apDiv1 {
position:absolute;
left:150px;
top:163px;
width:699px;
height:272px;
z-index:2;
}
.style5 {font-size: smaller; font-weight: bold; }
.style8 {font-weight: bold}
#apDiv2 {
position:absolute;
left:128px;
top:182px;
width:727px;
height:164px;
z-index:3;
}
#apDiv3 {
position:absolute;
left:149px;
top:637px;
width:725px;
height:631px;
z-index:4;
}
.style10 {
font-size: small;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style12 {color: #2A0055}
#list_tbl1 {
position:absolute;
left:148px;
top:503px;
width:726px;
height:174px;
z-index:4;
}
#tbl01 {
position:absolute;
left:147px;
top:503px;
width:730px;
height:508px;
z-index:4;
}
#apDiv4 {
position:absolute;
left:148px;
top:504px;
width:744px;
height:484px;
z-index:4;
}
.style14 {color: #000000}
.style16 {color: #000000; font-weight: bold; }
#apDiv5 {
position:absolute;
left:17px;
top:219px;
width:105px;
height:66px;
z-index:5;
}
#apDiv6 {
position:absolute;
left:127px;
top:442px;
width:742px;
height:196px;
z-index:4;
}
#apDiv7 {
position:absolute;
left:102px;
top:730px;
width:725px;
height:191px;
z-index:4;
}

-->
</style>
</head>

<body>
<div id="apDiv2">
  <p>

    <style type="text/css">
body{
    font-size:10pt;
    font-family:Arial,Tahoma,Verdana;
    color:#555;
}
table{
    background:#777;
    border:1px solid #cfcfcf;
}
td,th {
    background:#fff;
    padding:10px;
}
td {
    font-size:10pt;
}
form ul {
    list-style-type:none;
    width:250px;
}
form ul li {
    margin-top:1px;
    padding:10px;
    height:30px;
    border:1px solid #999;
}
strong.err {
    color:#930;
    display:block;
    margin:5px 0px;
}
#tab2 {
    margin-bottom:5px;
}
#tab2 input{
    border:0px;
    background:none;
}
  </style>
</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  
     <p>
       <?php
error_reporting(0);
    $batch = $_POST['batch_nr']; // Get batch textbox
    $person = $_POST['person_nr']; // Get person textbox
?>
     </p>
  <table width="177" border="1" cellpadding="2" cellspacing="1" bordercolor="#2A0000">
       <tr>
         <th width="119" align="left" bordercolor="#6E0067" bgcolor="#2A00AA" scope="row"><span class="style12">バッチ番号</span></th>
         <td width="41" align="center"><input name="batch_nr" type="text" id="batch_nr" value="<?php echo $batch; ?>" size="2" maxlength="3"></td>
       </tr>
       <tr>
         <th align="left" bordercolor="#6E0067" bgcolor="#2A00AA" scope="row"><span class="style12">バッチ人数</span></th>
         <td align="center"><input name="person_nr" type="text" id="person_nr" value="<?php echo $person; ?>" size="2" maxlength="3"></td>
       </tr>
     </table>

    <p class="style10">上記の条件でバッチメンバー登録表作成します </p>
     <p>
       <input type="submit" name="submit1" value="実行">
    </p>
  </form>



  
  
</div>



<div id="tbl01">
<?php
    if (isset($_POST['submit1'])) {
    $person = (int)$person;
        if($batch==''||$person=='')
            echo "<strong class='err'>Please ensure that \"Person nr.\" is a number</strong>";
        else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p class="style10">バッチメンバー登録表 </p>
  <span class="style10">「名前」、「ニックネーム」、「配属先会社コード」を入力してください</span>
      
    <table width="730" height="99" border="1" cellpadding="2" cellspacing="1" bordercolor="#2A0000" id="tab02">
    <tr>
      <th width="100" scope="col"><span class="style14">研修生番号</span></th>
      <th colspan="3" scope="col"><span class="style14">名前</span></th>
      <th width="108" scope="col"><span class="style14">ニックネーム</span></th>
      <th width="158" scope="col"><p class="style14">配属先会社コード</p></th>
    </tr>
    <tr>
      <td align="center"><span class="style16">Trainee code</span></td>
      <td width="95" align="center"><span class="style16">Sur Name</span></td>
      <td width="122" align="center"><span class="style16">Given Names</span></td>
      <td width="102" align="center"><span class="style16">Middle Name</span></td>
      <td align="center"><span class="style16">Nickname</span></td>
      <td align="center"><span class="style16">Company Code</span></td>
    </tr>
  
        
<?php
            for($i=1;$i<=$person;$i++) {
                echo "
                    <tr>
                        <td align='center'><input type='text' name='tc' value='{$batch}00{$i}' size='3' maxlength='3'></td>
                        <td align='center'><input type='text' name='sn' size='7'></td>
                        <td align='center'><input type='text' name='gn' size='7'></td>
                        <td align='center'><input type='text' name='mn' size='7'></td>
					<td align='center'><input type='text' name='nn' size='7'></td>
                        <td align='center'><input type='text' name='cc' size='4'></td>
                    </tr>
                ";
            }
        echo "

  </table>


        <input type='submit' name='submit2' value='Preview'>

        </form>

        ";

        }
    }
    
    if (isset($_POST['submit2'])) {
        // How to insert all the data from the texboxes in the mysql table???
        echo "

	I need here to list the data before inserting in the MySQL database table






	<table width='730' height='99' border='1' cellpadding='2' cellspacing='1' bordercolor='#2A0000' id='tab02'>
    <tr>
      <th width='100' scope='col'><span class='style14'>研修生番号</span></th>
      <th colspan='3' scope='col'><span class='style14'>名前</span></th>
      <th width='108' scope='col'><span class='style14'>ニックネーム</span></th>
      <th width='158' scope='col'><p class='style14'>配属先会社コード</p></th>
    </tr>
    <tr>
      <td align='center'><span class='style16'>Trainee code</span></td>
      <td width='95' align='center'><span class='style16'>Sur Name</span></td>
      <td width='122' align='center'><span class='style16'>Given Names</span></td>
      <td width='102' align='center'><span class='style16'>Middle Name</span></td>
      <td align='center'><span class='style16'>Nickname</span></td>
      <td align='center'><span class='style16'>Company Code</span></td>
    </tr>




</table>








	";		
}

?>


</body>
</html>

 

Thank you very much in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.