
tayys
Members-
Posts
21 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
tayys's Achievements

Newbie (1/5)
0
Reputation
-
tq AGuyWithAthing but where should I print out the set of javascript variables? is there any relevant example I can refer to?
-
hi there, I have a chained combo boxes. I manage to get the values for the sub process using onchange event.My problem here is how can I retain the values in the sub process combo box after the page is loaded? main.php <?php require_once 'connectDB.php'; $sub_id = $_GET['sub_id']; $id = $_SESSION['process_id']; $sql = " SELECT * FROM tb_process ORDER BY pro_id ASC"; $result = mysql_query($sql) or die(mysql_error()); $sql = "SELECT tb_record.rec_tpcd, tb_record.rec_part, tb_record.rec_code, tb_record.rec_vendor, tb_record.rec_location, tb_record.rec_remark, tb_sub_process.sub_name, tb_process.pro_name FROM tb_record LEFT JOIN tb_sub_process ON tb_record.sub_id=tb_sub_process.sub_id LEFT JOIN tb_process ON tb_sub_process.pro_id=tb_process.pro_id WHERE tb_sub_process.sub_id = '$sub_id'"; $result2 = mysql_query($sql); $row = mysql_fetch_assoc($result2); $pro_name = $row['pro_name']; $sub_name = $row['sub_name']; ?> <html> <head> <script type="text/javascript" src="js/ajax.js"></script> <script type="text/javascript" src="js/jquery-1.2.3.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#selectProcess").change(function() { var processID = $(this).val(); if(processID > 0) { $("#txtID").val(processID); $("#selectSubProcess").load('getSub.php?processID='+processID); } }); $("#selectSubProcess").change(function() { var subProcessID = $(this).val(); if(subProcessID > 0) { window.location = 'main.php?sub_id='+subProcessID; } }); }); </script> </head> <body> <form action="" method="post"> <table> <tr> <td>Process: </td> <td> <select id="selectProcess" name="selectProcess"> <option value="0" selected="selected">---SELECT PROCESS---</option> <?php while ($row = mysql_fetch_array($result)) { $process_id = $row['pro_id']; $process_name = $row['pro_name']; $select = ($id == $process_id) ? 'selected="selected"' : NULL; echo "<option value='$process_id' $select>$process_name</option>"; } ?> </select> </td> </tr> <tr> <td>Sub Process: </td> <td> <select id="selectSubProcess" name="selectSubProcess" > <option>SELECT PROCESS FIRST</option> </select> </td> </tr> </table> </form> <table border=1> <?php while($row = mysql_fetch_assoc($result2)) { extract($row); $imageDir1="images/".$rec_tpcd.".jpg"; $info = @getimagesize($imageDir1); if((bool)$info) { $imageDir="images/".$rec_tpcd.".jpg"; } else { $imageDir="images/NoPhoto.jpg"; } if ($col == 0) { $display .= "<tr>"; } $col++; if ($col == 1) { $col = 0; $display .= "</td>"; } echo "<tr> <td> <img src=$imageDir width='220' height='170' onClick=\"window.open('$imageDir', 'popup','height=500,width=800,scrollbars=yes,resizeable=yes status=yes'); return false\" target=\"_blank\"> </td> <td> <table style='overflow:auto; width:325px;'> <tr> <td width='80' valign='top'>Name</td> <td valign='top'>:</td> <td valign='top' colspan='2'>$rec_part</td> </tr> <tr> <td valign='top'>Code</td> <td valign='top'>:</td> <td valign='top' colspan='2'>$rec_code</td> </tr> <tr> <td>TPCD</td> <td>:</td> <td colspan='2'>$rec_tpcd</td> </tr> <tr class='style15'> <td>Vendor</td> <td>:</td> <td colspan='2'>$rec_vendor</td> </tr> <tr> <td>Location</td> <td>:</td> <td colspan='2'>$rec_location</td> </tr> <tr> <td>Remarks</td> <td>:</td> <td>$rec_remark</td> <td align='right'> <input type='image' name='change[$rec_tpcd]' src='library/cart add.png' width='20' height='20' value='Add To Order List >'/> </td> </tr> </table> </td> </tr>"; } ?> </table> </body> </html> getSub.php <?php require_once 'connectDB.php'; if(isset($_GET['processID'])) { $process_id = $_GET['processID']; $sql = " SELECT * FROM tb_sub_process WHERE pro_id = '$process_id' ORDER BY sub_id ASC"; $result = mysql_query($sql) or die(mysql_error()); $_SESSION['process_id'] = $process_id; echo "<option>---------------------SELECTION--------------------</option>"; while($row = mysql_fetch_assoc($result)) { $sub_process_id = strtoupper($row['sub_id']); $sub_process_name = strtoupper($row['sub_name']); echo "<option value='$sub_process_id'>$sub_process_name</option>"; } } ?>
-
prompt me if i m nt on the right track... thanks in advance.
-
Hi, I m trying to add items from a master list to each sub process. But, I failed to proceed on what i intend to do. 1) i need to select an process from the combo box. 2) from the master list, i hv to check the item which belong to the process. 3) upon submitting, save into database. 4) the it will show those are already checked or unchecked. here is the codes i hv done: <?php require_once '../../connectDB.php'; require_once '../include/paginator.class.php'; $sql="SELECT * FROM tb_item"; $result = mysql_query($sql) or die(mysql_error()); $pages = new Paginator; $pages->items_total = mysql_num_rows($result); $pages->mid_range = 5; $pages->items_per_page = 100; $pages->paginate(); $sql="SELECT * FROM tb_item ORDER BY itm_tcpd ASC $pages->limit"; $result = mysql_query($sql) or die(mysql_error()); function createComboBox() { $sql = "SELECT tb_process.pro_name, tb_process.pro_id, tb_sub_process.sub_id, tb_sub_process.sub_name FROM tb_process INNER JOIN tb_sub_process ON tb_process.pro_id = tb_sub_process.pro_id ORDER BY pro_name"; $result = mysql_query($sql) or die('Cannot get Process. ' . mysql_error()); $group = array(); while ($row = mysql_fetch_assoc($result)) { $group[$row['pro_name']][] = $row; } echo "<table> <tr> <td>Add item into :</td> <td> <select name='cboSub' id='cboSub'> <option value='0' selected='selected'>----- Selection -----</option>"; foreach ($group as $key => $values) { echo " <optgroup label='$key'>"; foreach ($values as $value) { $select = ($id == $value['sub_id']) ? 'selected="selected"' : NULL; echo '<option value="'.$value['sub_id'].'"'.$select.'>'.$value['sub_name'].'</option>'; } echo " </optgroup>"; } echo " </select> </td> </tr> </table>"; } if(isset($_POST['add'])) { $id = $_POST['checkbox']; foreach($id as $key=>$val) { $sql = "INSERT INTO tb_record (rec_tpcd, sub_id) VALUES ('$key', '$sub_id')"; $result = mysql_query($sql); } echo(" <SCRIPT LANGUAGE='JavaScript'> window.alert('Items has been added into the database.'); window.location='addItem.php'; </SCRIPT>"); } ?> <!DOCTYPE div PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript"> $().ready(function() { $("#cboSub").change("get_tpcd.php", { }); }); </script> </head> <body> <div> <table width="100%"> <tr> <td width="65%"><?php createComboBox(); ?></td> <td width="30%"><?php echo $pages->display_pages(); ?></td> <td width="5%"><?php echo $pages->display_jump_menu(); ?></td> </tr> </table> </div> <div> <form method='post' action=''> <table width='100%' border='1' align='left' cellpadding='5' cellspacing='1'> <tr> <?php $numCol = 5; $count = 0; for($i=0; $i<$numCol; $i++) { echo "<th align='center'>TPCD No.</th> <th align='center'>Check / Uncheck</th>"; } while ($row = mysql_fetch_array($result)) { extract($row); if($count % $numCol == 0) { echo '</tr><tr>'; } echo " <td align='center'>".$itm_tcpd."</td> <td align='right'><input type='checkbox' name='checkbox[".$itm_tcpd."]' id='checkbox' ".$checked."></td>"; $count++; } ?> </tr> <tr> <td colspan='10' align='right'> <input type='submit' name='add' id='add' value='Add TPCD'> </td> </tr> </table> </form> </div> </body> </html> the output is something similar as in the attachment. any helps are vy welcome and appreciated. regards, juz [attachment deleted by admin]
-
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
sure. I've created under the forum of javascript helps sometime last week. Here's the link to the new thread: http://www.phpfreaks.com/forums/index.php?topic=346236.0 any help is appreciated. -
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
noted. thank you very much for the guides and suggestions. I learnt a lot from you. *I would like to lift another issue regarding 2 chained combo boxes in jquery. r u able to give me some advises on that? -
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
jcbones, thanks dude. it's working perfectly now. despite, there is a statement i can't get myself clear. Can u please briefly explain these? $itm_keys = array_keys($_POST['change']); -
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
I tried the codes but it is shows the error message as in the attachment. I never encounter this seen this error message before. Any idea what's the problem is? Thanx. [attachment deleted by admin] -
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
Thanks for the response. I'll give it a try and let you know how it turns out! -
I'm not sure if I'm on the right track or not. Any advice would be appreciated. Thanks.
-
hi, I try to create 2 combo box where the second one will depends on the selection of the first one. But it failed to pass the value to cboSub upon the onchange="load();" of cboMain. Anyway I can fix it? Thanks in advance. Here's code for index.php: <?php require_once 'connectDB.php'; $id=$_GET['sub_id']; $sql="SELECT * FROM tb_process"; $result=mysql_query($sql); ?> <!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>OSSP-E-Store</title> <script language="JavaScript"> function load() { $("#cboMain").change(function() { $("#cboSub").load("getter.php?choice=" + $("#cboMain").val()); }); } </script> </head> <body> <form id="form1" name="form1" method="post"> <select name="cboMain" id="cboMain" onchange="load();"> <option value="0" selected="selected">----Select Main Process----</option> <?php while ($row = mysql_fetch_array($result)) { $pro_id = $row['pro_id']; $pro_name = $row['pro_name']; echo "<option value='$pro_id'>$pro_name</option>"; } ?> </select> <select name="cboSub" id="cboSub" onchange=""> <option value="0" selected="selected">----Select Sub Process----</option> </select> </form> </body> </html> Here's code for getter.php: <?php require_once 'connectDB.php'; $choice = mysql_real_escape_string($_GET['choice']); echo $choice; $query = "SELECT * FROM tb_sub_process WHERE pro_id='$choice'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $sub_id = $row['sub_id']; $sub_name = $row['sub_name']; $select = ($id == $sub_id) ? 'selected="selected"' : NULL; echo "<option value='$sub_id' $select>$sub_name</option>"; } ?>
-
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
ermm...maybe i m not clear here. here goes again. 1) the user will choose an option. 2) update to database by clicking a confirmation link next to it. 3) continue with other items with step 1&2. codes in list.php: <?php require_once '../../connectDB.php'; require_once '../include/functions.php'; $sql = " SELECT * FROM tb_item ORDER BY itm_id asc"; $result = mysql_query($sql) or die(mysql_error()); ?> <form> <h1>Items</h1> <table width="75%" border="1" align="left" cellpadding="5" cellspacing="1"> <tr> <th width="100" align="left">Item ID</th> <th width="100" align="left">Parts</th> <th width="100" align="left">Sub-Process</th> <th width="100" align="left">Confirmation</th> </tr> <tr> <?php while ($row = mysql_fetch_array($result)) { extract($row); ?> <td><?php echo $itm_id; ?></td> <td><?php echo $itm_parts; ?></td> <td> <select name='cboSub' id='cbosub'> <option value='' selected>---- Choose Process ----</option> <?php createComboBox($sub_id); ?> </select> </td> <td> <a href='processItem.php?itm_id=<?php echo $itm_id; ?>'> <img src='../images/modify.png' width='20' height='20' alt='confirm'/> </a> </td> </tr> <?php }; ?> </table> </form> <?php /** * Create combo box for sub-process */ function createComboBox($id) { $sql = " SELECT * FROM tb_sub_process ORDER BY sub_id asc"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); $select = ($id == $sub_id) ? 'selected="selected"' : NULL; echo "<option value='$sub_id' $select>$sub_name</option>"; } } ?> Codes in processItem.php: <?php $itm_id = isset($_GET['itm_id']) ? $_GET['itm_id'] : ''; $sub_id=$_POST['cboSub']; $sql = "UPDATE tb_item SET sub_id = '$sub_id' WHERE itm_id = '$itm_id'"; $result = mysql_query($sql) or die('Cannot update sub-process ID into tb_item. ' . mysql_error()); ?> how can I link these two sets of code together correctly? -
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
Sorry my mistake. It should be $sub_id=$_POST['cboSub']; But it still doesn't pass the selected value from the earlier page so that It can be updated into database based on the itm_id. -
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
thanx a lot jcbones...it works... I'm facing another problem. it wouldn't update into the database when i click on the confirmation link. it might be $_POST['cboSub'], cause i m getting a null value. what can i do to fix it right? here's my code on processItem.php: <?php $itm_id = isset($_GET['itm_id']) ? $_GET['itm_id'] : ''; $sub_id=$_POST['sub_id']; echo $sub_id; $sql = "UPDATE tb_item SET sub_id = '$sub_id' WHERE itm_id = '$itm_id'"; $result = mysql_query($sql) or die('Cannot update sub-process ID into tb_item. ' . mysql_error()); ?> -
how to show the option based on the value in the table?
tayys replied to tayys's topic in PHP Coding Help
here's my tables: *****tb_item***** itm_id | itm_qty | itm_cost | sub_id *****tb_process***** pro_id | pro_name *****tb_sub_process***** sub_id | sub_name | pro_name