Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 10th February 2011, 08:23
newphpcoder newphpcoder is offline
Junior Member
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in Duplication of data and onenter key

Good day!


I have 2 problems with my code 1st is in the last operation name or the 04 Oper it was duplicate but the duplicate was only the operation name and the rest data was blank . I tried to debug it but I ca'n find where is wrong in my syntax. And the 2nd problem is for the enter key function or array, because my textbox I used array, and to move on the next textbox i used enter key, the problem is on the last date when i press enter key instead of move the cursor on the shift textbox it was save. I want to happen is after the last date and I press enter key the cursor was on the shift textbox then after i input data in shift and i press enter key it will save.


Here is my code:


PHP Code:
<?php
 
if($rexist == 0)
                        {
                        
$query "SELECT t.operation_name, t.input_unit, t.output_unit FROM trace_operations t WHERE t.plt_typeno = '" $_POST["plt_typeno"] . "'  AND t.operation_name IN('02 Oper','03 Oper','04 Oper') ORDER BY t.operation_name";
                      
                        
$last_operation_name "";
                        
$result mysql_query($query);
                        if(
$result){
                        
$totalrows mysql_num_rows($result);
                        
$trows $totalrows 1;
                          for(
$ctr 0$ctr $trows$ctr++)
                           {
                          
$row mysql_fetch_array($result);
                          
$tctr $ctr 1;
                           echo 
"\n\t<tr>";
                           echo 
"\n\t\t<td width='800'>";
                           if (
$last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                            
$last_operation_name $row["operation_name"];
                            echo 
"<input type='hidden' width='400' name='opname[]' value='" $row["operation_name"] . "' /></td>";   
                            echo 
"\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["input_unit"];
                            echo 
"<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["output_unit"];
                            echo 
"<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varplt" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='varplt[]' id='varplt" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift" $ctr "\");' /></td>";
                           echo 
"\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"timein" $tctr "\");' /></td>";
                            echo 
"\n\t</tr>";
                            }
                       if(
$totalrows 1);
                            {
                            
$row mysql_fetch_array($result);
                            echo 
"\n\t<tr>";
                            echo 
"\n\t\t<td width='800'>";
                            if (
$last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                            
$last_operation_name $row["operation_name"];
                            echo 
"<input type='hidden' width='400' name='opname[]' value='" $row["operation_name"] . "' /></td>";   
                            echo 
"<input type='hidden' name='opname[]' value='" $row["operation_name"] . "' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["input_unit"];
                            echo 
"<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["output_unit"];
                            echo 
"<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varplt" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='varplt[]' id='varplt" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
                            echo 
"\n\t</tr>";
                            }
                        echo 
"</table>";
                        echo 
"<p><input type='submit' value='Save' id='saveform' /></p>";
                        echo 
"<input type='hidden' name='plt_typeno' value='" $_POST["plt_typeno"] . "' />";
                        }  
                        }  
?>

Any help is highly appreciated..

Thank you very much.. Ask me a question if my problem did not clear with you.:confused:


Again, Thank you so much
Reply With Quote
Sponsored Links
  #2  
Old 11th February 2011, 12:03
alleks alleks is offline
Senior Member
 
Join Date: Nov 2010
Posts: 157
Thanks: 9
Thanked 9 Times in 9 Posts
Default

You had an extra ";" on line 34, copy&paste and try it again

Code:
<?php 
	if($rexist == 0){ 
		$query = "SELECT t.operation_name, t.input_unit, t.output_unit FROM trace_operations t WHERE t.plt_typeno = '" . $_POST["plt_typeno"] . "'  AND t.operation_name IN('02 Oper','03 Oper','04 Oper') ORDER BY t.operation_name"; 
                       
		$last_operation_name = ""; 
		$result = mysql_query($query); 
		if($result){ 
			$totalrows = mysql_num_rows($result); 
			$trows = $totalrows - 1; 
	  		for($ctr = 0; $ctr < $trows; $ctr++){ 
				$row = mysql_fetch_array($result); 
			  	$tctr = $ctr + 1; 
			   	echo "\n\t<tr>"; 
			   	echo "\n\t\t<td width='800'>"; 
			   	if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
				$last_operation_name = $row["operation_name"];
				echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";    
				echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td>" . $row["input_unit"]; 
				echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td>" . $row["output_unit"]; 
				echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varplt" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"timein" . $tctr . "\");' /></td>"; 
				echo "\n\t</tr>"; 
			}
			if($totalrows > 1){ 
				$row = mysql_fetch_array($result); 
				echo "\n\t<tr>"; 
				echo "\n\t\t<td width='800'>"; 
				if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"]; 
				$last_operation_name = $row["operation_name"]; 
				echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";    
				echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td>" . $row["input_unit"]; 
				echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td>" . $row["output_unit"]; 
				echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varplt" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift\");' /></td>"; 
				echo "\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>"; 
				echo "\n\t</tr>"; 
			}
        	echo "</table>"; 
			echo "<p><input type='submit' value='Save' id='saveform' /></p>"; 
			echo "<input type='hidden' name='plt_typeno' value='" . $_POST["plt_typeno"] . "' />"; 
		}  
	}   
?>

Last edited by alleks; 11th February 2011 at 12:17.
Reply With Quote
  #3  
Old 14th February 2011, 03:03
newphpcoder newphpcoder is offline
Junior Member
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I copy and paste the revising code and the output is after the first shift it save
Reply With Quote
  #4  
Old 14th February 2011, 09:59
alleks alleks is offline
Senior Member
 
Join Date: Nov 2010
Posts: 157
Thanks: 9
Thanked 9 Times in 9 Posts
Default

I don't get it, be more specific. Any error?
Reply With Quote
  #5  
Old 14th February 2011, 10:14
newphpcoder newphpcoder is offline
Junior Member
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good day!

I attached my wholde code for better understanding in my problem. I tried to resolved my problem by tracing the codes and I trace it but I tried to resolved but nothing has change in my output still the 04 Oper was duplicated.

Here is the code where i think I have problem:

PHP Code:
                   

//If not existing the form will appear to insert data.

                    
if($rexist == 0)
                        {
                        
$query "SELECT t.operation_name, t.input_unit, t.output_unit FROM trace_operations t WHERE t.plt_typeno = '" $_POST["plt_typeno"] . "'  AND t.operation_name IN('02 Oper','03 Oper','04 Oper') ORDER BY t.operation_name";
                      


                        
$last_operation_name "";
                        
$result mysql_query($query);
                        if(
$result){

//in this code I think I have a problem why the last operation name was duplicated, but I have no idea how can i resolved it. I'm not good in analyzing and in the syntax condition code.

//in this code happened is the last operation_name was fetch in this for loop and also in the if condition below so it was duplicated. I want to happened is in the last operation name in false on the if condition so that it could not duplicated.
                       
$totalrows mysql_num_rows($result);
                       
$trows $totalrows 1;
                          for(
$ctr 0$ctr $trows$ctr++)
                           {
                          
$tctr $ctr 1;
                          
$row mysql_fetch_array($result);                          
                           echo 
"\n\t<tr>";
                           echo 
"\n\t\t<td width='800'>";
                           if (
$last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                            
$last_operation_name $row["operation_name"];
                            echo 
"<input type='hidden' width='400' name='opname[]' value='" $row["operation_name"] . "' /></td>";    
                            echo 
"\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>";
                          
                           echo 
"\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>";
                          
                           echo 
"\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["input_unit"];
                            echo 
"<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>";
                            
                            echo 
"\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["output_unit"];
                            echo 
"<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>";
                            
                            echo 
"\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>";
                           
                           echo 
"\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>";
                           
                            echo 
"\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varplt" $ctr "\");' /></td>";
                           
                            echo 
"\n\t\t<td><input size='6' type='text' name='varplt[]' id='varplt" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>";
                            
                            echo 
"\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift" $ctr "\");' /></td>";
                            
                           echo 
"\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"timein" $tctr "\");' /></td>";
                            echo 
"\n\t</tr>";

                            }
                            
                        }
                       if(
$totalrows 0);
                            {
                            
$row mysql_fetch_array($result);
                            echo 
"\n\t<tr>";
                            echo 
"\n\t\t<td width='800'>";
                            if (
$last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                            
$last_operation_name $row["operation_name"];
                            echo 
"<input type='hidden' width='400' name='opname[]' value='" $row["operation_name"] . "' /></td>";   
                            echo 
"<input type='hidden' name='opname[]' value='" $row["operation_name"] . "' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["input_unit"];
                            echo 
"<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td>" $row["output_unit"];
                            echo 
"<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varplt" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='varplt[]' id='varplt" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift\");' /></td>";
                            echo 
"\n\t\t<td><input size='6' type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
                            echo 
"\n\t</tr>";
                            }
                        echo 
"</table>";
                        echo 
"<p><input type='submit' value='Save' id='saveform' /></p>";
                        echo 
"<input type='hidden' name='plt_typeno' value='" $_POST["plt_typeno"] . "' />";
                        }  
                       
                        
                    } 
Attached Files
File Type: txt whole_code.txt (20.1 KB, 83 views)
Reply With Quote
  #6  
Old 14th February 2011, 10:57
alleks alleks is offline
Senior Member
 
Join Date: Nov 2010
Posts: 157
Thanks: 9
Thanked 9 Times in 9 Posts
Default

put this in your index.php at the very beginning and check for errors in your page, and post the here.

PHP Code:
<?php

error_reporting
(E_ALL);
ini_set("display_errors"1);
Reply With Quote
  #7  
Old 15th February 2011, 01:37
newphpcoder newphpcoder is offline
Junior Member
 
Join Date: Dec 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

I put the code that you given and the output is:

Notice: Undefined index: plt_no in D:\xampp\htdocs\PLT\yield_station2.php on line 15

Notice: Undefined index: enum_plt in D:\xampp\htdocs\PLT\yield_station2.php on line 98

Notice: Undefined index: enum_plt in D:\xampp\htdocs\PLT\yield_station2.php on line 149

Notice: Undefined index: plt_no in D:\xampp\htdocs\PLT\yield_station2.php on line 170
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:16.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.