Bind Table and a Textbox

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gracepinas
Forum Newbie
Posts: 15
Joined: Sat Aug 15, 2009 1:04 am

Bind Table and a Textbox

Post by gracepinas »

Hello

I was able to connect my Table from my sql database using the code below

my problem is i want to bind this table into a textbox so that if i click a row in the table...it will automaticall display in an input
value
is this the right way? colored in red
Please Help

Code: Select all

<?php
 
 include("common/payroll_con.php");
 
    $TableName = "tblemployee";
    $SQLstring = mysql_query("SELECT * from $TableName");
 
    //$Row = mysql_fetch_row($SQLstring);
        //echo  "<div id=\"users\">";
        echo "<div id=\"lblUser\">Employee Code</div>";
        echo "<div id=\"lblName\">Employee   Name</div>";
        echo "<div id=\"userlist\" >&nbsp;";
        echo "<table style=\"margin:0 auto;\" width:\"100%\" margin-top:\"-15px\">";
       while ($Row = mysql_fetch_array($SQLstring)) {
        echo "<tr style=\"background:white;\">";
   [color=#800000]    echo "<td><a href=\"$PHP_SELF?id={$Row['empcode']}\"><span id=\"liUser\">{$Row['empcode']}</span><span id=\"liName\">{$Row['ename']}</span></a></td>";[/color]
         echo  "</tr>";
        }
 
        echo "</table>";
      echo "</div>";
    
 
 ?>

Code: Select all

<input name="" type="text" value="<? echo $Row['empcode']?>" id="textbox"/>
gracepinas
Forum Newbie
Posts: 15
Joined: Sat Aug 15, 2009 1:04 am

Re: Bind Table and a Textbox

Post by gracepinas »

Heres the interface can you please help me

I want the table to display in my textboxes when a row in the table is clicked
Attachments
Table-textbox.JPG
Table-textbox.JPG (22.9 KiB) Viewed 221 times
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Bind Table and a Textbox

Post by Griven »

It's good to see you're making progress on this app!

You may want to change line 16 to the following:

Code: Select all

echo "<td><a href=\"". $_SERVER['PHP_SELF'] ."?id={$Row['empcode']}\"><span id=\"liUser\">{$Row['empcode']}</span><span id=\"liName\">{$Row['ename']}</span></a></td>";
The change there is the PHP_SELF variable. Its correct format, unless it's been pre-assigned to a custom variable, is $_SERVER['PHP_SELF']. This will now make your link submit the page back to itself with the attached id variable in the GET array.

The next step from there is to create an IF statement that wraps around your form. That statement should check to see if the $_GET['id'] variable is set and valid. If it is, then a query is run against your database to select all data from the row where the employee ID is equal to the one in the GET array. For example:

Code: Select all

 if (isset($_GET['id']) && is_numeric($_GET['id'])) { //Your id may not be numeric, but you get the idea
 
$id = mysql_real_escape_string($_GET['id']);
$query = "SELECT * FROM tblemployee WHERE empcode = $id";
$result = mysql_query($query);
$array = mysql_fetch_assoc($result);
 
//Build your form from here, populating it with data from $array.  
//Remember, you can escape PHP and print HTML if it is easier.  
//You don't have to echo everything.
 
}
gracepinas
Forum Newbie
Posts: 15
Joined: Sat Aug 15, 2009 1:04 am

Re: Bind Table and a Textbox

Post by gracepinas »

hello thanks for the help i forgot to tell ...if i will click the table and display it on the textbox... i have ajax and xml to load my forms without refreshing the page is this how i do it?

Code: Select all

<a href=\"". $_SERVER['PHP_SELF'] ."?id={$Row['empcode']}\" onclick=\"javascript&#058;showModule('MasterFile.php','subid=0','get')\">
this is how we open the form without refreshing

Code: Select all

javascript&#058;showModule('MasterFile.php','subid=0','get')
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Bind Table and a Textbox

Post by Griven »

Unfortunately, I can't help you with anything javascript-related, as I don't know enough about it. You may want to check with an AJAX specific forum.
gracepinas
Forum Newbie
Posts: 15
Joined: Sat Aug 15, 2009 1:04 am

Re: Bind Table and a Textbox

Post by gracepinas »

thanks so much
Post Reply