Jump to content

update table with array


Slowie

Recommended Posts

hey guys im really stuck and need help with this. im trying to update a mysql table from an array.

 

basically i have 12 records what are pulled using a query. each record has its own ID to distinguish it from the rest. i then have 2 tick boxes for the user to select one for accept and one for deny. what i need is for the query to look at each record on the table and insert the selection boxes value if ticked.

 

my code is below but i have altered it to the hilt and cannot get it to work :( so please help  :D :D :D :D :D

 

<?php 
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/Apollo/dbc.php";
include_once($path);



$rs_results = mysql_query("SELECT * FROM off WHERE IsItAuthorised='0' and isitsick='0' ORDER BY DayOff");

?>
<html>
<head>
<title>Administration Main Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php



if (isset($_POST['submit'])) {
//Assign each array to a variable
$id = $_POST['id'];
$approve = $_POST['approve'];
$deny = $_POST['deny'];


$limit = count($id);




$values = array(); // initialize an empty array to hold the values
for($k=0;$k<$limit;$k++){
$msg[] = "$limit Holidays Updated";
$id[k] = $id;
$approve[k] = $approve;
$deny[k] = $deny;

$id = implode($id);
$approve = implode( $approve);
$deny = implode( $deny);

	  $query = "UPDATE off SET Authorised = $approve , Deny = $deny
	  WHERE OffID =  $id " ;
}



$Event = "INSERT INTO events (UserName, Event ) VALUES ('$_SESSION[user_name]', 'Entered New KPI' )";	
								  



	echo $query;
if (!mysql_query($query,$link)){
	die('Error: ' . mysql_error());
} else {

	mysql_query($Event);
	echo "<div class=\"msg\">" . $msg[0] . "</div>";
}




}							  
?>


</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="14%" valign="top"><?php

?>

</td>
    <td width="74%" valign="top" style="padding: 10px;">
      
      <p><?php 
  if(!empty($msg)) {
  echo $msg[0];
  }
  ?></p>

      <p>
        <?php 
  $cond = '';



  


  $sql = "select * from off ";
  

  
  $rs_total = mysql_query($sql) or die(mysql_error());
  $total = mysql_num_rows($rs_total);
  
  	  
  ?>
       
      <p>
     
	<form name "searchform" action="/Apollo/Admin/HolidayRequests.php" method="post">
        <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
          <tr class="mytables"> 
            <td width="4%"><font color="white"><strong>ID</font></strong></td>
            <td width="4%"> <font color="white"><strong>Staff Member</font></strong></td>
            <td width="10%"><font color="white"><strong>Day Off</font></strong></div></td>
		 <td width="10%"><font color="white"><strong>Is It Authorized</font></strong></div></td>
            <td width="15%"> </td>
          </tr>
	  
	  
          <tr> 
            <td> </td>
            <td width="10%"> </td>
            <td width="17%"><div align="center"></div></td>
            <td> </td>
          </tr>
          <?php while ($rrows = mysql_fetch_array($rs_results)) {?>
          <tr> 
            <td><input name="id[]" id="id[]" size="4" value="<?php echo $rrows['OffID'];?>" /></td>
            <td><?php echo $rrows['StaffMember']; ?></td>
            <td><?php echo date('d/m/Y', strtotime($rrows['DayOff']));?></div></td>
            
            <td> <span id="approve<?php echo $rrows['id']; ?>"> 
              <?php if(!$rrows['IsItAuthorised']) { echo "Pending"; } else {echo "Authorized"; }?>
              </span> </td>
		  
		  <td>
		  
      
		<input type="hidden" name="approve[]" id="approve[]" value="0">
		<input type="checkbox" name="approve[]" id="approve[]" value="1"> Approve
		<input type="hidden" name="deny[]" id="deny[]" value="0">
		<input type="checkbox" name="deny[]" id="deny[]" value="1"> Deny


	 </td>
          </tr>
     
          <?php } ?>
        </table>
      <input name="submit" type="submit" id="submit" value="Submit">
      </form>
  

       </p>
  <?php


  ?>
  

      <p> </p>
      <p> </p>
      <p> </p>
      <p> </p></td>
    <td width="12%"> </td>
  </tr>
</table>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.