Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Retrieving data from database and displaying in textbox when the button click
Old 01-04-2011, 02:07 AM Retrieving data from database and displaying in textbox when the button click
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
I search about the code for retrieving data from database when the retrieve button was click. But I can’t find any codes that similar in my situation.

Here is the flow of my system. I have plt_no and a retrieve button. The retrieve button is to check if the plt_no is already exist or not if it is already exist the data from the database will appear in the text area/textbox and if the plt_no did not exist there’s a message that the id number did not exist and I can input data in the textboxes.


I have an idea of using this code:
This code is to check if the Retrieve button is click and the plt_no is the data which the retrieve depend on. Like for example the user put plt_no 111 and when the user click the Retrieve button, if the 111 is already exist the data will appear in the textboxes but if not there’s a message appear saying the plt no did not exist.

Code:
if(isset($_POST['Retrieve']))
$plt_no = $_POST['plt_no'];



And I have search code for retrieving data:

PHP Code:
 
<?php 
 
// Connects to your Database 
 
mysql_connect("your.hostaddress.com""username""password") or die(mysql_error()); 
 
mysql_select_db("Database_Name") or die(mysql_error()); 
 
$data mysql_query("SELECT * FROM friends WHERE pet='Cat'"
 or die(
mysql_error()); 
 Print 
"<table border cellpadding=3>"
 while(
$info mysql_fetch_array$data )) 
 { 
 Print 
"<tr>"
 Print 
"<th>Name:</th> <td>".$info['name'] . "</td> "
 Print 
"<th>Color:</th> <td>".$info['fav_color'] . "</td> "
 Print 
"<th>Food:</th> <td>".$info['fav_food'] . "</td> "
 Print 
"<th>Pet:</th> <td>".$info['pet'] . " </td></tr>"
 } 
 Print 
"</table>"
 
?>


I attach my full code.

My problem is how can I used that code and if that code is the code I need to used for retrieving data.



I have an idea but i am luck of knowledge in coding

Any help is highly appreciated I ma willing to learn and share

Thank you
Attached Files
File Type: txt retrieve.txt (12.8 KB, 3 views)
newphpcoder is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-04-2011, 03:45 AM Re: Retrieving data from database and displaying in textbox when the button click
Novice Talker

Posts: 9
Name: Rohan Chopdekar
Trades: 0
The easiest way for you to do it is to set the Value property of textbox using any php variable.

<Input type="Text" name="Pet" value=" <?php echo $info['pet'] ?> ">

i suppose this is what you wanted.

Last edited by rohan210; 01-04-2011 at 03:52 AM..
rohan210 is offline
Reply With Quote
View Public Profile
 
Old 01-04-2011, 03:58 AM Re: Retrieving data from database and displaying in textbox when the button click
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
I want is only the data view if I retrieve data. and if no data retrieve the textboxes was blank

Thank you
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 01-04-2011, 05:16 AM Re: Retrieving data from database and displaying in textbox when the button click
Novice Talker

Posts: 9
Name: Rohan Chopdekar
Trades: 0
OK then you should try this.. Only if-else should suffice
PHP Code:
<Input type="Text" name="Pet" value=" <?php if(empty($info['pet'])){echo '';}else {echo $info['pet'];}?> ">
Let me know if u find this helpful!!

Last edited by rohan210; 01-04-2011 at 05:51 AM..
rohan210 is offline
Reply With Quote
View Public Profile
 
Old 01-04-2011, 07:27 PM Re: Retrieving data from database and displaying in textbox when the button click
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Did you see the attached file which is my full code where i want to add the code for retrieve?

Thank you
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 01-04-2011, 08:06 PM Re: Retrieving data from database and displaying in textbox when the button click
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
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($resultMYSQL_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($resultMYSQL_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>&nbsp;</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>&nbsp;</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
newphpcoder is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Retrieving data from database and displaying in textbox when the button click
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47449 seconds with 13 queries