Jump to content

Archived

This topic is now archived and is closed to further replies.

takeiteasy

Checkbox For Edit

Recommended Posts

Dear all,
Now my problem is i wanted to edit my record when i check the checkbox. So if i check the checkbox and click the Edit link, the data will be post to the edit page for edit.I don't know wad name i should give to the checkbox so it can sort of represent the row of data. Hope kind souls out there can help me with this! Thanks in advance!


[code]
<TABLE width="90%" BORDER="0" align="center" cellpadding="3">
         <!-- <table width="80%" border="0" align="center" cellpadding="5" cellspacing="0" class="tableborder"> -->
<a href="show_addrecord.php">Add</a>  <a href="edit.php">Edit</a>   <a href="delete.php">Delete</a>       <a href ="">Save In Archive</a>
<?
// Begin table outside of the array
echo "<table width='90%' align='center' border='0' class='tableborder' bgcolor='#9FD2EC' cellpadding='5' cellspacing='0'>
    <tr>
<td width='20' bgcolor='$row_color' nowrap>
    
    <td width='60' bgcolor='$row_color' nowrap>
     <strong>RefID</strong>
    <td width ='190' bgcolor='$row_color'>
     <strong>Employer Name</strong>
    <td width ='190' bgcolor='$row_color'>
     <strong>Worker Name</strong>
    <td bgcolor='$row_color'>
     <strong>Outstanding Loans</strong>
    </td>

    </tr>";
echo "</table>";

echo "<table width='90%' align='center' class='descborder' cellpadding='5'>";

// Define colors for the alternating rows

$color1 = "#C6E6F7";  
$color2 = "#E1F4FD";  
$row_count = 0;

// Perform an statndard SQL query:

$results = mysql_query("SELECT empRef, empName, workerName FROM airticketbooking order by empRef asc") or die (mysql_error());

// use the "$row" method for this query.

while ($row = mysql_fetch_array($results)) {
    $empRef = $row["empRef"];
    $empName = $row["empName"];
    $workerName = $row["workerName"];
    $empRef = $row["empRef"];

    /* Now we do this small line which is basically going to tell  
    PHP to alternate the colors between the two colors we defined above. */

    $row_color = ($row_count % 2) ? $color1 : $color2;

    // Echo table row and table data that want to be looped over and over here.

    echo "<tr>
   <td width='20' bgcolor='$row_color' nowrap>
    <input type='checkbox'>
    <td width='60' bgcolor='$row_color' nowrap>
    $empRef
    <td width ='190' bgcolor='$row_color'>
    <a href='display.php'> $empName </a>
    <td bgcolor='$row_color'>
     $workerName
    <td bgcolor='$row_color'>
     $$empRef
    </td>
    </tr>";


    // Add 1 to the row count

    $row_count++;
}

// Close table.

echo "</table>";

?>[/code]

Share this post


Link to post
Share on other sites
assign the empRef as the name of the checkbox, as from what i can tell that should be a unique reference number, so can easily be used to call that record from your table.

PS. you have $row[empRef] twice in your while loop. :)

Share this post


Link to post
Share on other sites
so issit like this?
<input type='checkbox' name='empRef'>
but how do i noe if the checkbox links with the selected data?

ya i know abot the while loop $row[empRef] being called twice...i just put there temporary...coz i still have another problem which i have yet sort out...

Thanks so much!

Share this post


Link to post
Share on other sites
<input type='checkbox'>
should normaly be

<input type='checkbox' name='empRef' value='$empRef ' >

I'm taking it that empRef is the unique IDin your table.. Also remember your going to need FORM above and below your loop of data and a submit button on the last field so should look like this..

[code]
<TABLE width="90%" BORDER="0" align="center" cellpadding="3">
         <!-- <table width="80%" border="0" align="center" cellpadding="5" cellspacing="0" class="tableborder"> -->
<a href="show_addrecord.php">Add</a>  <a href="edit.php">Edit</a>   <a href="delete.php">Delete</a>       <a href ="">Save In Archive</a>
<?
//here you are going to need your query and if statement to grab the ID from the checkbox and display a text box to edit that row of data in..

// Begin table outside of the array
echo "<table width='90%' align='center' border='0' class='tableborder' bgcolor='#9FD2EC' cellpadding='5' cellspacing='0'>
    <tr>
<td width='20' bgcolor='$row_color' nowrap>
    
    <td width='60' bgcolor='$row_color' nowrap>
     <strong>RefID</strong>
    <td width ='190' bgcolor='$row_color'>
     <strong>Employer Name</strong>
    <td width ='190' bgcolor='$row_color'>
     <strong>Worker Name</strong>
    <td bgcolor='$row_color'>
     <strong>Outstanding Loans</strong>
    </td>

    </tr>";
echo "</table>";
echo "<form action='' method='POST' name='editform'>";
echo "<table width='90%' align='center' class='descborder' cellpadding='5'>";

// Define colors for the alternating rows

$color1 = "#C6E6F7";  
$color2 = "#E1F4FD";  
$row_count = 0;

// Perform an statndard SQL query:

$results = mysql_query("SELECT empRef, empName, workerName FROM airticketbooking order by empRef asc") or die (mysql_error());

// use the "$row" method for this query.


while ($row = mysql_fetch_array($results)) {
    $empRef = $row["empRef"];
    $empName = $row["empName"];
    $workerName = $row["workerName"];


    /* Now we do this small line which is basically going to tell  
    PHP to alternate the colors between the two colors we defined above. */

    $row_color = ($row_count % 2) ? $color1 : $color2;

    // Echo table row and table data that want to be looped over and over here.

    echo "<tr>
   <td width='20' bgcolor='$row_color' nowrap>
    <input type='checkbox' name='empRef' value='$empRef '>
    <td width='60' bgcolor='$row_color' nowrap>
    $empRef
    <td width ='190' bgcolor='$row_color'>
    <a href='display.php'> $empName </a>
    <td bgcolor='$row_color'>
     $workerName
    <td bgcolor='$row_color'>
     $$empRef
    </td>
    </tr>";


    // Add 1 to the row count

    $row_count++;
}
// Close table.

echo "</table>";

//change colour for submit button line-table

$row_color = ($row_count % 2) ? $color1 : $color2;

//echo table with just submit button in

echo "
<table width='90%' align='center' class='descborder' cellpadding='5'>
   <tr>
      <td width='60' bgcolor='$row_color' nowrap>
         <input type='submit' name='submit' value='Submit'>
      </td>
   </tr>
</table>
</form>";


?>
[/code]

I also deleted 1 line of $empRef = $row["empRef"]; as you had it defined twice :)


added form, deleted $empRef = $row["empRef"];, added new table with submit button.. your table could do with </td> at the end of each bit of text e.g.

<td width='20' bgcolor='$row_color' nowrap>
<input type='checkbox' name='empRef' value='$empRef '>
</td>


this will close it off else it will be leaving <td> open which could cause formatting problems.

Hope this helps

Regards
Liam

Share this post


Link to post
Share on other sites
Thanks for your help shocker-z!

But i think i dun need the submit button. This page intend to be my index page and wad i intend to do is...when i checked the checkbox, press the Edit button, it will appear the edit page where it will display the initial records ready for edit.

i get wad i trying to say?haha...
so sorry...need your help again.

Share this post


Link to post
Share on other sites
You need to submit the form so that it will pass the data over to your edit page. Unless you're prepared to use AJAX, which makes it a whole lot more work.

Share this post


Link to post
Share on other sites

×

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.