update checkbox with repeat region


capture.jpg

 

this picture within repeat region. wish update checkbox in repeat region database, idea if checkbox checked update status returned else update status on loan.

 

 

code shown below.

is idea correct text in red? tried doesn't work.

 

 

 

<?php require_once('connections/myconnection2.php'); ?>
<?php
if (!function_exists("getsqlvaluestring")) {
function getsqlvaluestring($thevalue, $thetype, $thedefinedvalue = "", $thenotdefinedvalue = "")
{
  if (php_version < 6) {
    $thevalue = get_magic_quotes_gpc() ? stripslashes($thevalue) : $thevalue;
  }

  $thevalue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($thevalue) : mysql_escape_string($thevalue);

  switch ($thetype) {
    case "text":
      $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null";
      break;   
    case "long":
    case "int":
      $thevalue = ($thevalue != "") ? intval($thevalue) : "null";
      break;
    case "double":
      $thevalue = ($thevalue != "") ? doubleval($thevalue) : "null";
      break;
    case "date":
      $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null";
      break;
    case "defined":
      $thevalue = ($thevalue != "") ? $thedefinedvalue : $thenotdefinedvalue;
      break;
  }
  return $thevalue;
}
}

$currentpage = $_server["php_self"];

$editformaction = $_server['php_self'];
if (isset($_server['query_string'])) {
  $editformaction .= "?" . htmlentities($_server['query_string']);
}

if ((isset($_post["mm_update"])) && ($_post["mm_update"] == "form2"))
for($startrow_recordset1=1;$startrow_recordset1<$totalrows_recordset1;$startrow_recordset1 ++)

{
  $updatesql = sprintf("update `change` set status=%s `change_id`=%s",
                       getsqlvaluestring(isset($_post['checkbox']) ? "true" : "", "defined","returned","on loan"),
                       getsqlvaluestring($_post['change_id'], "int"));

  mysql_select_db($database_myconnection2, $myconnection2);
  $result1 = mysql_query($updatesql, $myconnection2) or die(mysql_error());

  $updategoto = "query.php";
  if (isset($_server['query_string'])) {
    $updategoto .= (strpos($updategoto, '?')) ? "&" : "?";
    $updategoto .= $_server['query_string'];
  }
  header(sprintf("location: %s", $updategoto));
}


$maxrows_recordset1 = 10;
$pagenum_recordset1 = 0;
if (isset($_get['pagenum_recordset1'])) {
  $pagenum_recordset1 = $_get['pagenum_recordset1'];
}
$startrow_recordset1 = $pagenum_recordset1 * $maxrows_recordset1;

$colname_recordset1 = "-1";
if (isset($_get['box1'])) {
  $colname_recordset1 = $_get['box1'];
}
mysql_select_db($database_myconnection2, $myconnection2);
$query_recordset1 = sprintf("select * `change`,owner,requester,device c_made %s , `change`.owner_id= owner.o_id , `change`.requester_id=requester.r_id , `change`.device_id=device.d_id", getsqlvaluestring("%" . $colname_recordset1 . "%", "text"));
$query_limit_recordset1 = sprintf("%s limit %d, %d", $query_recordset1, $startrow_recordset1, $maxrows_recordset1);
$recordset1 = mysql_query($query_limit_recordset1, $myconnection2) or die(mysql_error());
$row_recordset1 = mysql_fetch_assoc($recordset1);

if (isset($_get['totalrows_recordset1'])) {
  $totalrows_recordset1 = $_get['totalrows_recordset1'];
} else {
  $all_recordset1 = mysql_query($query_recordset1);
  $totalrows_recordset1 = mysql_num_rows($all_recordset1);
}
$totalpages_recordset1 = ceil($totalrows_recordset1/$maxrows_recordset1)-1;

$querystring_recordset1 = "";
if (!empty($_server['query_string'])) {
  $params = explode("&", $_server['query_string']);
  $newparams = array();
  foreach ($params $param) {
    if (stristr($param, "pagenum_recordset1") == false &&
        stristr($param, "totalrows_recordset1") == false) {
      array_push($newparams, $param);
    }
  }
  if (count($newparams) != 0) {
    $querystring_recordset1 = "&" . htmlentities(implode("&", $newparams));
  }
}
$querystring_recordset1 = sprintf("&totalrows_recordset1=%d%s", $totalrows_recordset1, $querystring_recordset1);
?>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>untitled document</title>
<style type="text/css">
#form1 table {
color: #d6d7d6;
}
#form1 table {
color: #000;
}
#form1 {
text-align: left;
}
.centre {
text-align: center;
}
#recordset {
text-align: center;
}
</style>
</head>

<body>
<h2>results of search ""</h2>
<form id="form2" name="form2" method="post" action="<?php echo $editformaction; ?>">
  <p> </p>
  <p> </p>
  <table width="800" border="2" align="center">
    <tr>
      <th scope="col">id</th>
      <th scope="col"><span class="centre">part changed</span></th>
      <th scope="col"><span class="centre">change</span></th>
      <th scope="col"><span class="centre">date changed</span></th>
      <th scope="col"><span class="centre">owner</span></th>
      <th scope="col"><span class="centre">requester</span></th>
      <th scope="col"><p>device type</p></th>
      <th scope="col">network</th>
      <th scope="col">previous status</th>
      <th scope="col"><p>current status</p>
      <p>(returned?)</p></th>
      <th scope="col"> </th>
      <th scope="col"> </th>
      <th scope="col"> </th>
    </tr>
    <?php { ?>
    <tr>
      <td><input name="change_id" type="text" id="change_id" value="<?php echo $row_recordset1['change_id']; ?>" readonly="readonly" /></td>
      <td><?php echo $row_recordset1['part_changed']; ?></td>
      <td><span class="centre"><?php echo $row_recordset1['c_made']; ?></span></td>
      <td><?php echo $row_recordset1['date changed']; ?></td>
      <td><a href="results_ownerdet.php?o_id=<?php echo $row_recordset1['o_id']; ?>"><?php echo $row_recordset1['o_name']; ?></a></td>
      <td><span class="centre"><a href="results_reqdet.php?r_id=<?php echo $row_recordset1['r_id']; ?>"><?php echo $row_recordset1['r_name']; ?></a></span></td>
      <td><a href="results_devicedet.php?d_id=<?php echo $row_recordset1['d_id']; ?>"><?php echo $row_recordset1['type']; ?></a></td>
      <td><?php echo $row_recordset1['network']; ?></td>
      <td><?php echo $row_recordset1['status']; ?></td>
      <td><input name="checkbox" type="checkbox" id="checkbox" value="1" <?php if (!(strcmp($row_recordset1['status'],1))) {echo "checked=\"checked\"";} ?> /></td>
      <td> </td>
      <td><a href="update_entry.php?change_id=<?php echo $row_recordset1['change_id']; ?>">edit</a></td>
      <td><a href="delete_entry.php?change_id=<?php echo $row_recordset1['change_id']; ?>">delete</a></td>
    </tr>
    <?php } while ($row_recordset1 = mysql_fetch_assoc($recordset1)); ?>
  </table>
  <p>
    <input type="submit" name="update" id="update" value="update checkbox" />
  </p>
  <input type="hidden" name="mm_update" value="form2" />
</form>
<p> </p>
<p> </p>
<p>records <?php echo ($startrow_recordset1 + 1) ?> <?php echo min($startrow_recordset1 + $maxrows_recordset1, $totalrows_recordset1) ?> of <?php echo $totalrows_recordset1 ?> </p>
<p>
<table border="0" align="center">
  <tr>
    <td><?php if ($pagenum_recordset1 > 0) { // show if not first page ?>
        <a href="<?php printf("%s?pagenum_recordset1=%d%s", $currentpage, 0, $querystring_recordset1); ?>">first</a>
        <?php } // show if not first page ?></td>
    <td><?php if ($pagenum_recordset1 > 0) { // show if not first page ?>
        <a href="<?php printf("%s?pagenum_recordset1=%d%s", $currentpage, max(0, $pagenum_recordset1 - 1), $querystring_recordset1); ?>">previous</a>
        <?php } // show if not first page ?></td>
    <td><?php if ($pagenum_recordset1 < $totalpages_recordset1) { // show if not last page ?>
        <a href="<?php printf("%s?pagenum_recordset1=%d%s", $currentpage, min($totalpages_recordset1, $pagenum_recordset1 + 1), $querystring_recordset1); ?>">next</a>
        <?php } // show if not last page ?></td>
    <td><?php if ($pagenum_recordset1 < $totalpages_recordset1) { // show if not last page ?>
        <a href="<?php printf("%s?pagenum_recordset1=%d%s", $currentpage, $totalpages_recordset1, $querystring_recordset1); ?>">last</a>
        <?php } // show if not last page ?></td>
  </tr>
</table>
</p>
<p><a href="query.php" class="centre">proceed query page</a></p>
<p><a href="aquery.php">proceed advanced query page</a></p>
<p> </p>
</body>
</html>
<?php
mysql_free_result($recordset1);
?>

you can create javascript function redirect update record page.

 

<script type="text/javascript"> function update_status(record_id) {   var record_id;   window.location= 'update.php?id='+record_id; } </script>

 

you need update recordset calls javascript function during onclick. don't know record's id called record_id

 

<td><input name="checkbox" type="checkbox" id="checkbox" value="1" onclick="update_status(<?php echo $row_recordset1['record_id']; ?>);" <?php if (!(strcmp($row_recordset1['status'],1))) {echo "checked=\"checked\"";} ?> /></td> 

 

now update.php check see if current status value returned new value should blank or not returned, else value returned. can build udpate sql statement id = $_get['id']



More discussions in Develop server-side applications in Dreamweaver


adobe

Comments

Popular posts from this blog

How to decompile jsxbin to jsx

Gavik Photoslide GK2: Not able to upload photos - Joomla! Forum - community, help and support

Phoca Guestbook logger registret bruger af - Joomla! Forum - community, help and support