Jump to content


Photo

Checkbox For Edit


  • Please log in to reply
5 replies to this topic

#1 takeiteasy

takeiteasy
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 26 April 2006 - 05:56 AM

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!


<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>"; 

?>


#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 26 April 2006 - 08:40 AM

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. :)
wisewood: proven fact, I am both wise, and wooden.

#3 takeiteasy

takeiteasy
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 26 April 2006 - 08:48 AM

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!

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 26 April 2006 - 08:55 AM

<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..

<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>"; 


?>

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
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 takeiteasy

takeiteasy
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 26 April 2006 - 09:35 AM

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.

#6 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 26 April 2006 - 09:44 AM

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.
wisewood: proven fact, I am both wise, and wooden.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users