| newphpcoder |
5Jan2011 06:48 |
Re: Retrieving data from database and displaying in textbox when the button click
I have the code I want to add for retrieving data:
PHP Code:
$query = "SELECT plt_no FROM plt_transact WHERE plt_no= '" . $_POST["plt_no"] . "'"; $result = mysql_query($query) or die ("Error in query: $query " . mysql_error()); $row = mysql_fetch_array($result); $num_results = mysql_num_rows($result); if ($num_results > 0) { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
Is it that code is right?for retrieving data?
My question is it automatically that when I insert plt_no then i click retrieve button it plt_no is exist the data will appear in the textboxes but I don't know how can I appear it and if the plt_no did not exist the textboxes is blank and theres a message that saying plt no did not exist.
PHP Code:
if($_POST["enum_plt"] && $_POST["plt_typeno"]) { $query = "SELECT * FROM plt_type WHERE plt_typeno = '" . $_POST["plt_typeno"] . "'"; $result = mysql_query($query); if($result) { $rexist = 1;
$query = "SELECT plt_no FROM plt_transact WHERE plt_no= '" . $_POST["plt_no"] . "'"; $result = mysql_query($query) or die ("Error in query: $query " . mysql_error()); $row = mysql_fetch_array($result); $num_results = mysql_num_rows($result); if ($num_results > 0) { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<p>PLT No:<input type='text' name='plt_no' onkeypress='return handleEnter(event,\"plt_date\");' /></br />"; echo "PLT Date:<input type='text' name='plt_date' onkeypress='return handleEnter(event,\"bom0\");' /></p>"; echo "<p><input type='Button' value='Retrieve' id='Retrieve' name='Retrieve' /></p>"; echo "<table>"; $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><input type='text' name='bom[]' id='bom" . $ctr . "' onkeypress='return handleEnter(event,\"qty" . $ctr . "\");' /></td>"; echo "\n\t\t<td>" . $row["plt_chemicals"]; echo "<input type='hidden' name='chem[]' value='" . $row["plt_chemicals"] . "' /></td>"; echo "\n\t\t<td><input type='text' name='qty[]' id='qty" . $ctr . "' onkeypress='return handleEnter(event,\"part" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='part[]' id='part" . $ctr . "' onkeypress='return handleEnter(event,\"lot" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='lot[]' id='lot" . $ctr . "' onkeypress='return handleEnter(event,\"bom" . $tctr . "\");' /></td>"; echo "\n\t</tr>"; } if($totalrows > 1); { $row = mysql_fetch_array($result); echo "\n\t<tr>"; echo "\n\t\t<td><input type='text' name='bom[]' id='bom" . $ctr . "' onkeypress='return handleEnter(event,\"qty" . $ctr . "\");' /></td>"; echo "\n\t\t<td>" . $row["plt_chemicals"]; echo "<input type='hidden' name='chem[]' value='" . $row["plt_chemicals"] . "' /></td>"; echo "\n\t\t<td><input type='text' name='qty[]' id='qty" . $ctr . "' onkeypress='return handleEnter(event,\"part" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='part[]' id='part" . $ctr . "' onkeypress='return handleEnter(event,\"lot" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='lot[]' id='lot" . $ctr . "' onkeypress='return handleEnter(event,\"b1\");' /></td>"; echo "\n\t</tr>"; } echo "</table>"; echo "<p> </p>"; echo "<table>"; echo "<tr><td>B1</td><td><input type='text' name='b1' id='b1' onkeypress='return handleEnter(event,\"sc2\");' /></td></tr>"; echo "<tr><td>SC2</td><td><input type='text' name='sc2' id='sc2' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>"; echo "</table>"; echo "<p> </p>"; $query = "SELECT * FROM trace_operations WHERE plt_typeno = '" . $_POST["plt_typeno"] . "' AND operation_name IN ('Operation1' , 'Operation2' , 'Operation3')ORDER BY operation_name"; $last_operation_name = ""; $result = mysql_query($query); if($result) { $rexist = 1; echo "<table>"; $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>"; if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"]; $last_operation_name = $row["operation_name"]; echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>"; echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input 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 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 type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varplt" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input 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>"; if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"]; $last_operation_name = $row["operation_name"]; echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>"; echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>"; echo "\n\t\t<td><input type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input 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 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 type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varplt" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='varplt[]' id='varplt" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>"; echo "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift\");' /></td>"; echo "\n\t\t<td><input type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>"; echo "\n\t</tr>"; } echo "</table>"; } } } } }
this code is incomplete, can someone told me what is the missing code to view the retrieve data?and how does the retrieve works.
Thank you
|