joshtheflame Posted August 16, 2009 Share Posted August 16, 2009 Hi All, i am new to PHP and developing a php form in which I have two DIV and in right hand side DIV i have a tabular data fetched from a table in shape of grid and in left hand side DIV i have a form. Now i want to do is when i click on a row it should fetch the current row customer ID (displayed in grid) and show the whole record in a form (left hand side) which I can update later on. How to do this using AJAX and javascript. sample code is below. Please help me. thanks <?php require_once('Connections/crplconnect.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"]; $maxRows_customerRS = 10; $pageNum_customerRS = 0; if (isset($_GET['pageNum_customerRS'])) { $pageNum_customerRS = $_GET['pageNum_customerRS']; } $startRow_customerRS = $pageNum_customerRS * $maxRows_customerRS; mysql_select_db($database_crplconnect, $crplconnect); $query_customerRS = "SELECT c_id, cbname, cbowner, cityid, cpcontact FROM customers ORDER BY cbname ASC"; $query_limit_customerRS = sprintf("%s LIMIT %d, %d", $query_customerRS, $startRow_customerRS, $maxRows_customerRS); $customerRS = mysql_query($query_limit_customerRS, $crplconnect) or die(mysql_error()); $row_customerRS = mysql_fetch_assoc($customerRS); if (isset($_GET['totalRows_customerRS'])) { $totalRows_customerRS = $_GET['totalRows_customerRS']; } else { $all_customerRS = mysql_query($query_customerRS); $totalRows_customerRS = mysql_num_rows($all_customerRS); } $totalPages_customerRS = ceil($totalRows_customerRS/$maxRows_customerRS)-1; $queryString_customerRS = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_customerRS") == false && stristr($param, "totalRows_customerRS") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_customerRS = "&" . htmlentities(implode("&", $newParams)); } } $queryString_customerRS = sprintf("&totalRows_customerRS=%d%s", $totalRows_customerRS, $queryString_customerRS); ?> <!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> <link rel="stylesheet" type="text/css" href="css/admincss.css"/> <link rel="stylesheet" type="text/css" href="css/usage.css"/> <style type="text/css"> <!-- #customerform h3 { color: #004080; } #customerform h3 { color: #804000; } --> </style> </head> <body> <div id="customerform"> <table id="box-table-a" width="507" border="0"> <tr> <form id= "customerForm" action="" method="get"> <td width="199" align="right" class="vzebra-odd" id="leftcolumn">Customer ID</td> <td width="271" align="left" class="vzebra-odd"> <label> <input type="text" name="txtCustID" id="txtCustID" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Business Name</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtbname" id="txtbname" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Owner Name</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtOwner" id="txtOwner" /> </label> </td> </tr> <tr> <td height="50" align="right" class="vzebra-odd" id="leftcolumn">Address</td> <td align="left" class="vzebra-odd"> <label> <textarea name="txtAddress" cols="40" id="txtAddress"></textarea> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Phone</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtPhone" id="txtPhone" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Mobile</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtMobile" id="txtMobile" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Fax</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtFax" id="txtFax" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">URL</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtUrl" id="txtUrl" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Company Email</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtCemail" id="txtCemail" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">City</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtCity" id="txtCity" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Primar Contact Name</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtcpContact" id="txtcpContact" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Primary Contact Email</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtcpEmail" id="txtcpEmail" /> </label> </td> </tr> <tr> <td align="right" class="vzebra-odd" id="leftcolumn">Password</td> <td align="left" class="vzebra-odd"> <label> <input type="text" name="txtPassword" id="txtPassword" /> </label> </form></td> </tr> </table> </div> <div id="customergrid"> <table id="rounded-corner" border="0"> <thead> <tr> <th class="rounded-company" scope="col">Client ID</th> <th class="rounded-q1" scope="col">Client Name</th> <th class="rounded-q2" scope="col">Owner Name</th> <th class="rounded-q3" scope="col">City</th> <th class="rounded-q4" scope="col">Primary Contact</th> </tr> </thead> <tfoot> <tr> <td colspan="4" class="rounded-foot-left"><em>Please select any row</em></td> <td class="rounded-foot-right"> </td> </tr> </tfoot> <tbody> <?php do { ?> <tr> <td><?php echo $row_customerRS['c_id']; ?></td> <td><?php echo $row_customerRS['cbname']; ?></td> <td><?php echo $row_customerRS['cbowner']; ?></td> <td><?php echo $row_customerRS['cityid']; ?></td> <td><?php echo $row_customerRS['cpcontact']; ?></td> </tr> <?php } while ($row_customerRS = mysql_fetch_assoc($customerRS)); ?> </table> <table width="719" border="0"> <tr> <td align="center" valign="middle"><table width="218" border="0" align="center"> <tr> <td><?php if ($pageNum_customerRS > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_customerRS=%d%s", $currentPage, 0, $queryString_customerRS); ?>"><img src="images/First.gif" border="0" /></a> <?php } // Show if not first page ?></td> <td><?php if ($pageNum_customerRS > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_customerRS=%d%s", $currentPage, max(0, $pageNum_customerRS - 1), $queryString_customerRS); ?>"><img src="images/Previous.gif" border="0" /></a> <?php } // Show if not first page ?></td> <td><?php if ($pageNum_customerRS < $totalPages_customerRS) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_customerRS=%d%s", $currentPage, min($totalPages_customerRS, $pageNum_customerRS + 1), $queryString_customerRS); ?>"><img src="images/Next.gif" border="0" /></a> <?php } // Show if not last page ?></td> <td><?php if ($pageNum_customerRS < $totalPages_customerRS) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_customerRS=%d%s", $currentPage, $totalPages_customerRS, $queryString_customerRS); ?>"><img src="images/Last.gif" border="0" /></a> <?php } // Show if not last page ?></td> </tr> </table></td> </tr> <tr> <td align="center">Records <?php echo ($startRow_customerRS + 1) ?> to <?php echo min($startRow_customerRS + $maxRows_customerRS, $totalRows_customerRS) ?> of <?php echo $totalRows_customerRS ?></td> </tr> </table> <p> </p> <blockquote> <blockquote> <blockquote> <blockquote> <h5 align="center"> </h5> </blockquote> </blockquote> </blockquote> </blockquote> </div> </body> </html> <?php mysql_free_result($customerRS); ?> Link to comment https://forums.phpfreaks.com/topic/170529-php-ajax-how-to-get-values-from-a-tabular-grid-into-a-form/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.