PHP - How To Delete Lines From A Txt File Based On Checkbox Selection
Hey all need some help with the subject title.
Have a user text file with all information(Name, address, passwords, etc..) Need to be able to select the user based on Checkbox selection then hit delete button and all users checked will be removed from the txt file and thus removed from HTML page. Im using PHP to show contents of the txt file into my HTML page. So far i have: <?php $file = fopen("user.txt","r"); echo '<table border="0" width="100%"> <tr> <th>Select</th> <th>Username</th> <th>Password</th> <th>FirstName</th> <th>LastName</th> <th>Email</th> <th>Address</th> </tr> '; while(!feof($file)) { $user = explode(":", fgets($file)); echo '<tr> <td><input type="checkbox" name="chkDelete" id = "chkDelete" value="select" /></td> <td>' . $user[0] . '</td> <td>' . $user[1] . '</td> <td>' . $user[2] . '</td> <td>' . $user[3] . '</td> <td>' . $user[4] . '</td> <td>' . $user[5] . '</td> </tr>'; echo '</table>'; fclose($file); ?> Am unsure as to how i would go about doing this, help would be greatly appreciated! Thanks in advanced, Daniel. Similar TutorialsHi! What i can't figure out, is how to delete between 2 given strings in another file. Explanation: I have a file, it contains following: Code: [Select] ### Start of content 0 ### Some Radom Lines with text 1 ### End of content 0 ### ### Start of content 1 ### Some Radom Lines with text 2 ### End of content 1 ### ### Start of content 2 ### Some Radom Lines with text 3 ### End of content 2 ### And so on, now i need code, which can find line i give and delete between. Something like this: If, i give string: Code: [Select] ### Start of content 0 ### Then it will delete this line to the Code: [Select] ### End of content 0 ### Hope you can help! All the best: Mart L. Extremely new here and to PHP and I have exhausted my newbie resources and my brain on this one. Concept: Cron Job to INSERT 5 lines per hour (Not the whole list at once) Script to read a pipe delimited text file (about 5k Lines) Open File Get last (bottom) 5 lines of file, ignore the rest Insert those 5 lines into my database Open File, Remove last (bottom) 5 lines I am able to do parts 1-3 but not part 4 (removing last 5 lines) Please help me! Code: [Select] $data = array_slice(file('data.txt'), -5); foreach($data as $value) { $fields=explode("|",$value); $num=count($fields); for ($n=0;$n<$num;$n++) { $null=""; print ($n==0) ? "Importing Video...<BR>" : $null; } // Insert into tmpvideos table here include("includes/config.php"); $last_id_result = @mysql_query( @"SELECT ext_id FROM tmpvideos ORDER BY ext_id+0 DESC, id DESC" ); if ( 0 < @mysql_num_rows( $last_id_result ) ) { $last_id = @mysql_result( $last_id_result, 0, "ext_id" ) + 1; } else { $last_id = "1"; } copy($fields[3], "thumbs/ex_".$last_id.".jpg" ); $fields[3] = "thumbs/ex_".$last_id.".jpg"; set_time_limit(0); mysql_query("INSERT into tmpvideos (id, ext_id, title, description, duration, category, date_added, thumb, video, views, rating, votes, status) VALUES ('','".$last_id."','$fields[0]','$fields[1]','$fields[5]','$fields[6]',NOW(),'$fields[3]','$fields[2]','','','','1')"); } I understand the 'concept' but am unable to grasp the code! I have tried many snippets and really need help. Hi All, I am creating a page where a customer can create a new order from a list of items. All the data is stored in a MySQL database and is accessed by PHP. What I am trying to achieve is the following: Starting with one row as shown below: The customer can then select a product from the list and the details appear in the following rows as shown he The customer should then be able to add another row by pressing the + button or delete that row by pressing the - button. At the moment I have got the system to work as far as one row goes with the data being placed into the rows using AJAX. I have then tried to add new rows/delete rows etc. but have had little success and have pretty much hit a brick wall. I would greatly appreciate it if someone could take a look and point me in the right direction! Thanks! The code for the above project is shown below: neworder.php Code: [Select] <table id="dataTable" style="margin-left:22px;margin-top:30px;"> <thead> <tr class="odd"> <th style="text-align:center;"scope="col" abbr="Add/Delete"><INPUT style="width:25px" TYPE="button" VALUE="+" onClick="addRow('dataTable')"/></th> <th scope="col" abbr="Qty">Quantity</th> <th scope="col" abbr="Code">Product Code</th> <th scope="col" abbr="Argus Code">Argus Product Code</th> <th scope="col" abbr="Desc">Description</th> <th scope="col" abbr="Rate">Rate</th> <th scope="col" abbr="Amount">Amount</th> <th scope="col" abbr="VAT">VAT</th> </tr> </thead> <tbody id="txtHint"> <tr class="odd"> <td style="text-align:center;"><INPUT style="width:25px" TYPE="button" VALUE="-" onClick="deleteRow('dataTable')"></td> <td><input style="width:40px" type="text" value="1" name="quantity<? echo $num; ?>"/></td> <td><form><select name="products" onchange="showProductList(this.value, <?php echo getCustNum($custname); ?>)"><option value="">Select a product:</option><?php $products = mysql_query("SELECT * FROM products"); while($getproducts = mysql_fetch_array($products)){ echo '<option value='.$getproducts['ProductCode'].'>'.$getproducts['ProductCode'].' - '.$getproducts['ArgusProductCode'];} ?></select></form></td> <td><?php echo $argusproductcode; ?></td> <td><?php echo $description; ?></td> <td style="text-align:right;"><? echo $rate; ?></td> <td style="text-align:right;"><? //echo $amount; ?></td> <td><?php echo $vat; ?></td> </tr> </tbody> <tfoot> <tr><td></td> <td></td> <td></td> <td></td> <td>Sub-total</td> <td style="text-align:right;"><?php echo getSubTotal($ponum); ?></td> <td></td> <td></td> </tr> <tr><td></td> <td></td> <td></td> <td></td> <td>VAT</td> <td style="text-align:right;"><?php echo getVATCost($ponum); ?></td> <td></td> <td></td> </tr> <tr><td></td> <td></td> <td></td> <td></td> <td>TOTAL</td> <td style="text-align:right;">£<?php echo number_format((getSubTotal($ponum)+getVATCost($ponum)), 2, '.', ''); ?></td> <td></td> <td></td> </tr> </tfoot> </table> JS/XML for the data to be placed in the rows: Code: [Select] function showProductList(str, str2) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getproductlist.php?q="+str+"&c="+str2,true); xmlhttp.send(); } getproductlist.php <?php include("db.php"); include("functions.php"); $q = $_GET["q"]; $c = $_GET["c"]; $productcode = $q; $q1 = getProductID($productcode); $counter = 1; $result = mysql_query("SELECT * FROM products WHERE ProductCode = '$productcode'"); $result2 = mysql_query("SELECT * FROM customerPrices WHERE CustNum = '$c' AND ProductID = '$q1'"); while($row = mysql_fetch_array($result)) { while($row2 = mysql_fetch_array($result2)) { //while(counter > 0) //{ $argusproductcode = $row['ArgusProductCode']; $description = $row['Description']; $rate = $row2['Rate']; $vat = $row2['VAT']; echo '<tr class="odd"> <td style="text-align:center;"><input style="width:25px" type="button" value="-" onClick="deleteRow(\'dataTable\')"></td> <td><input style="width:40px" type="text" value="1" name="quantity'.$num.'"/></td> <td><form>'.$productcode.'</form></td> <td>'.$argusproductcode.'</td> <td>'.$description.'</td> <td style="text-align:right;">'.$rate.'</td> <td style="text-align:right;">'.$amount.'</td> <td>'.$vat.'</td> </tr>'; //} } } ?> JS for Adding/Deleting Rows (Although some of this is probably garbage!) Code: [Select] function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; rowCount = rowCount - 3; var row = table.insertRow(rowCount); row.id = "row"; document.getElementById("row").className = "odd"; var cell1 = row.insertCell(0); var delbutton = document.createElement("input"); delbutton.type = "button"; delbutton.style.textAlign = "center"; delbutton.style.width = "25px"; delbutton.value = "-"; cell1.appendChild(delbutton); var cell2 = row.insertCell(1); var quantity = document.createElement("input"); quantity.type = "text"; quantity.style.width = "40px"; quantity.value = "1"; cell2.appendChild(quantity); var cell3 = row.insertCell(2); var cell4 = row.insertCell(3); var cell5 = row.insertCell(4); var cell6 = row.insertCell(5); var cell7 = row.insertCell(6); var cell8 = row.insertCell(7); } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=1; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox) { table.deleteRow(i); rowCount--; i--; } } }catch(e) { alert(e); } } Thanks again! 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: Code: [Select] <?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] Hi guys! im new to phpfreaks *waving*
im trying to delete row from a table that is populated by data from database using checkbox(and it doesnt matter if its just one checkbox or multiple) but its not working, as in nothing happens. no delete, no errors or warnings, just a refresh.
table:
<form class="event-button-wrap" method="post" action="event.php"> <div class="button-wrap"> <input type="submit" id="del_event" name="del_event" value="Delete Event"/> </div> <div class="event-list-table2" > <table class="event-table"> <thead> <tr> <th>Event Name</th> <th class="head">Event Date</th> <th class="head">Venue</th> </tr> </thead> <tbody class="tbody-event-list-table2"> <?php require "connection.php"; $check = mysql_query("SELECT * FROM event"); if(mysql_num_rows($check) > 0) { while($row = mysql_fetch_array($check)) { $id = $row['event_id']; $name = $row['event_name']; $dstart = $row['start_date']; $venue = $row['event_venue']; echo "<tr> <td> <input type='checkbox' name='check[]' class='check' value='$id'>$name </td> </tr>"; } } else { echo "<tr> <td colspan='4'>There Are No Events.</td> </tr>"; } ?> </tbody> </table> </div> </form>process is before <!DOCTYPE html>: <?php if(isset($_POST['del_event'])) { if(isset($_POST['check'])) { foreach($_POST['check'] as $del_id) { $del_id = (int)$del_id; require "connection.php"; $sqlqueer = mysql_query("DELETE FROM event WHERE event_id = $del_id"); if($sqlqueer) { echo "<meta http-equiv=\"refresh\" content=\"0;URL=event.php\">"; } } } ?>thanks in advance! Good day: I am tryint to redirect back to a page based on non selection. I am using this code, it is redirecting but not passing the $aid variable on the url. The page is getting the passed variable before doing the redirect. Here is the code: Code: [Select] if ($_POST['hid']==0) { header('Location: sample.php?aid=."$aid"'); } Thanks in advance. I manage to display data using below query that will show value for each month. How to calculate average value starting july onwards(based on user selection).
Let say the value for element 'A' are Jul=80, Aug= 80, Sep=90. If user select Aug then the average is 80 and if user select Sep then the average is 83.
Query:
$sql2 = "Select element, SUM(CASE WHEN Month = 'Jan' THEN total ELSE 0 END ) AS Jan, SUM(CASE WHEN Month = 'Feb' THEN total ELSE 0 END ) AS Feb, SUM(CASE WHEN Month = 'Mac' THEN total ELSE 0 END ) AS Mac, SUM(CASE WHEN Month = 'Apr' THEN total ELSE 0 END ) AS Apr, SUM(CASE WHEN Month = 'May' THEN total ELSE 0 END ) AS May, SUM(CASE WHEN Month = 'Jun' THEN total ELSE 0 END ) AS Jun, SUM(CASE WHEN Month = 'Jul' THEN total ELSE 0 END ) AS Jul, SUM(CASE WHEN Month = 'Aug' THEN total ELSE 0 END ) AS Aug, SUM(CASE WHEN Month = 'Sep' THEN total ELSE 0 END ) AS Sep, SUM(CASE WHEN Month = 'Oct' THEN total ELSE 0 END ) AS Oct, SUM(CASE WHEN Month = 'Nov' THEN total ELSE 0 END ) AS Nov, SUM(CASE WHEN Month = 'Dec' THEN total ELSE 0 END ) AS Dis FROM tbl_ma GROUP BY element"; $rs2 = mysql_query($sql2); $getRec2 = mysql_fetch_assoc($rs2);Below is how print the data: <?php while ($row = mysql_fetch_assoc($rs2)) { ?> <tr> <td style="color:black;background-color:#f5efef"><div align="left"><?php echo $row['element']; ?></div></td> <?php if( $year != '2014' ){ ?> <?php if( 1 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Jan']; ?></div></td><?php endif; ?> <?php if( 2 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Feb']; ?></div></td><?php endif; ?> <?php if( 3 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Mac']; ?></div></td><?php endif; ?> <?php if( 4 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Apr']; ?></div></td><?php endif; ?> <?php if( 5 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['May']; ?></div></td><?php endif; ?> <?php if( 6 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Jun']; ?></div></td><?php endif; ?> <?php } ?> <?php if( 7 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Jul']; ?></div></td><?php endif; ?> <?php if( 8 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Aug']; ?></div></td><?php endif; ?> <?php if( 9 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Sep']; ?></div></td><?php endif; ?> <?php if( 10 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Oct']; ?></div></td><?php endif; ?> <?php if( 11 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Nov']; ?></div></td><?php endif; ?> <?php if( 12 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Dis']; ?></div></td><?php endif; ?> <td><div align="center" style="color:black"><?php //echo average; ?></div></td> </tr> <?php } ?> Hello all, looking for some help here as I seem to be fairly stuck... this yields no results at all and I give up, I need help!
The user should be able to select an employee from a select field, and based on their selected we should be able to grab the start time and end time of that empoyee, which resides on the database.
My form:
<form action=".php" name="absence" id="absence" method="post"> Employee: <select name="empid" class="clockinputs" required> <option value=""></option> <option value='20'>Bob Jones</option> <option value='13'>Bob Phones</option> <option value='93'>Bob Lomes</option> <option value='30'>Bob Somes</option> <option value='107'>Bob Pomes</option> <option value='74'>Bob Womes</option> </select> Shift Start: <input type="text" name="startshift" id="startshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required> Shift End: <input type="text" name="endshift" id="endshift" class="clockinputs" data-inputmask="'mask': '99:99:99'" required> <input type="hidden" name="eid" value="<?php echo $row{'EID'}; ?>"> <input type="submit" value="Save"> </form>Javascript: <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('#empid').live('change', function(event) { $.ajax({ url : 'absence-get.php', type : 'POST', dataType: 'json', data : $('#absence').serialize(), success: function( data ) { for(var id in data) { $(id).val( data[id] ); } } }); }); }); </script>And absence-get.php: <?php $e = $_POST['empid']; $result = mysql_query("SELECT * FROM employees WHERE EID='$e' "); $row = mysql_fetch_array($result, MYSQL_ASSOC) $startshift = $row{'startshift'}; $endshift = $row{'endshift'}; $arr = array( 'input#startshift' => $startshift , 'input#endshift' => $endshift ); echo json_encode( $arr ); ?>Anyone spot anything? Thank you! Hello, I am trying to update my database with multiple array values like this. if (isset($_POST['submit_multiple'])) { $id=$_POST['selector']; $class=$_POST['class']; $section=$_POST['section']; $N = count($id); for($i=0;$i<$N;$i++) { echo "update table1 set transfer_status='yes',transfer_date='".date('Y-m-d')."',class='".$class[$i]."',section='".$section[$i]."' where enroll_no='".$id[$i]."'"; }and in the form <form action="transfer_mul_student.php" method="post"><select name="class[]"> <option value="">--SELECT CLASS--</option> <option value="Nursery">Nursery</option> <option value="LKG">LKG</option> <option value="UKG">UKG</option> <option value="I">I</option> <option value="II">II</option> <option value="III">III</option> <option value="IV">IV</option> </select> <select name="section[]"><option value="">--SELECT SECTION--</option> <option value="A">A</option> <option value="B">B</option> <option value="C">C</option> </select><input name="selector[]" id="selector" type="checkbox" value="<?php echo $row['enroll_no']; ?>" /> <input type="submit" class="delete_multiple" value="Transer" name="submit_multiple" />Here $row['enroll_no']is from table student. I have attached the screenshot for the page display with form err1.PNG 12.04KB 0 downloads, In that If i select checkbox1, checkbox2 checkbox3.. it takes the value for class and section properly, but if i select checkbox1, checkbox3, it takes value for 1st record properly and for 2nd one it takes blank value for class and section. How to overcome this? Please suggest Hello, is it possible to define the next page after a form submission based on a value from the form ? Example: My form has a dropdown Value 1: Flight Value 2: Flight + Hotel now i'm trying to achieve that if value 1 is chosen after submission it goes to flight.php, if value 2 it should go to flighthotel.php or am i heading into the completely wrong direction here and over complicating things ? Thanks in advance ! Hello, i want to reproduce a content switcher based on drop-down menu (example: http://www.infocercetare.ro/index.php) anyone can help me with the logic of the function the rest i think i can handle. best regards Hello, i have a form with a dropdown selection with the values 1 to 8, on the submit page i have another form which has 8 divs, now i want to show only a number of those divs based on the selection of the dropdown from the previous page. example: 1st page dropdown value is 4, form gets submitted, on the next page show div 1 & 2 & 3 & 4, and so on. Is this possible? /Edit: i just thought about it again and i think i could use Code: [Select] <?php $dropdown=$_POST['dropdown']; if($dropdown=="1") { ?> around the div tags, but then i would have to make 8 forms and take out 1 div one by one based on the dropdown selection, or is my thinking wrong? Good day and Merry Christmas to all, I just spent a good time of my christmas eve trying to figure out this problem. I hope one of you santas would be so kind as to help me with it. First off I have two tables; employee and employee_works both connected via employee_id key. Basically I have a parent window we'll call parent.php. inside the parent page is a search button that once clicked will open a child window we'll call child.php inside the child page is a list, lets say employees with name, employee_id, etc. My main concern is this: How do I populate parent.php based off the employee selection I made in the child window. Example: -Access parent.php -Click on search -Click on [ID: 004] [NAME: JOHN SMITH] [PHONE: 1233456] [DATE HIRED: JULY 16, 1992] <---format of a row in child.php -child.php automatically closes and parent.php now shows all data from employee_works with the employee_id = 004 Is this even possible? I know this is vary vague and would be willing to explain more if needed. My website is built mostly on javascript and php. I have 10 tables in my database. I want load these 10 table names into a drop-down list. If a user selects a value form the drop-down list, a form should be displayed with related to the table. (form fields should be appropriate table's column headers) When user fill the form and submitted, data should be saved in the selected table. Give me a code example to do this. I have a dynamic script and need to create a click event function with JavaScript to delete the row which has a checkbox checked when the delete button is pressed. This is being implemented with PHP and as now serves as light code for this matter at hand. I was only able to delete all rows. I have my efforts with the js functions too. <script type="text/javascript"> var counter = 1; var limit = 6; function addTextArea() { if (counter == limit-1) { alert("Maximum limit " + counter + " sorry"); return false; } else { <!-- CAUTION THIS IS BACKWARDS. --> var newdiv = document.createElement('div'); newdiv.innerHTML = "" + (counter + 1) + " <br><textarea name='fav_det[]' id=counter rows='3' cols='20'>"; document.getElementById('div6').appendChild(newdiv); var newdiv = document.createElement('div'); newdiv.innerHTML = "" + (counter + 1) + " <br><textarea name='fav_col' id=counter rows='3' cols='20'>"; document.getElementById('div5').appendChild(newdiv); var newdiv = document.createElement('div'); newdiv.innerHTML = "" + (counter + 1) + " <br><textarea name='fav_mod[]' id=counter rows='3' cols='20'>"; document.getElementById('div4').appendChild(newdiv); var newdiv = document.createElement('div'); newdiv.innerHTML = " " + (counter + 1) + " <br><input type='text' name='truck[]' id=counter>"; document.getElementById('div3').appendChild(newdiv); var newdiv = document.createElement('div'); newdiv.innerHTML = " " + (counter + 1) + " <br><input type='text' name='car[]' id=counter>"; document.getElementById('div2').appendChild(newdiv); var newdiv = document.createElement('div'); newdiv.innerHTML = "" + (counter + 1) + " <br><input type='checkbox' name='chk[]' id=counter>"; document.getElementById('div1').appendChild(newdiv); counter++ return true; } } </script> <script type="text/javascript"> function deleteRowS(dataTable) { for (var rowi= table.rows.length; rowi-->0;) { var row= table.rows[rowi]; var inputs= row.getElementsByTagName('dataTable'); for (var inputi= inputs.length; inputi-->0;) { var input= inputs[inputi]; if (input.type==='checkbox' && input.checked) { row.parentNode.removeChild(row); break; } } } } </script> <script type="text/javascript"> function deleteRow() { var table = document.getElementById(tableID).tBodies[0]; var rowCount = table.rows.length; // var i=1 to start after header for(var i=1; i<rowCount; i++) { var row = table.rows[i]; // index of td contain checkbox is 8 var chkbox = row.cells[6].getElementsByTagName('input')[0]; if('checkbox' == chkbox.type && true == chkbox.checked) { table.deleteRow(i); } } }</script> </head> <table> <tr><td valign='top'><b>NEED DELETE ROW WITH CHECKBOX FUNCTION:</td></tr> </table> <table id="dataTable" width="auto" style="margin:-4px 0 0 0; padding:14px 0 0 0;" cellspacing="10px"><tbody id="dataTable"></tbody> <tr> <td valign='Top'> ✗ <div id="div1"> <input type="checkbox" name="chk[]" autocomplete="off" id="1" > </div> </td> <td valign='Top'> cars <div id="div2"> <input type="text" name="car[]" id="2" > </div> </td> <td valign='Top'> trucks <div id="div3"> <input type="text" name="truck[]" id="3" > </div> </td> <td valign='Top'> your favorite model <div id="div4"> <textarea name="mod[]" id="4" rows="3" cols="20"></textarea> </div> <br><br> </td> <td valign='Top'> your favorite add-ons <div id="div5"> <textarea name="fav_col" id="5" rows="3" cols="20"></textarea> </div> </td> <td valign='Top'> explain vehicle overall <div id="div6"> <textarea name="fav_det" id="6" rows="3" cols="20"></textarea> </div> </td> </tr> </table> <input type="button" value="Add another" onClick="addTextArea();" /> <input type="button" value="Delete row" onclick="deleteRow('dataTable');deleteRowS('dataTable')" /> This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=349871.0 Hello, I had 8 select boxes(dropdowns) in a form. Its like a search kind of implementation in the website. I don't know what the user selects, he may choose different select boxes, any number of select boxes. So, based upon the user selection, I need to generate the data. The data fields to be generated would be almost same. So, How would I know what the user selection is and how many select boxes has been selected and how could I generate different data based upon selected boxes. I had to make a small note abt this, that the data generation fields may change for some of the user select combinations, but most of the result fields would be same. so, can you please help me out, how to do, how to make different combination data generations, because, i had 8 fields, i had to make 8! combinations, that would result in a big code. Maybe some of the great coders here can help this noob out. So here is what I have so far: Code: [Select] //set age criteria for deletion $age = 60; //get current date $datenow = date("Y-m-d"); //set the range we want to delete $delete_range = $datenow - $age; //get old user_id from users table $oldusers_users = mysql_query ("SELECT user_id FROM users WHERE lastvisit < $delete_range "); //get user_id from images table that correspond to users table $oldusers_images = mysql_query ("SELECT user_id FROM images WHERE $oldusers_users=user_id.images "); //find folders that correspond to the usernames and delete $oldusers_files = mysql_query ("SELECT username FROM users WHERE lastvisit < $delete_range "); //print out username //$result = mysql_($oldusers_files); $foldername = mysql_result($oldusers_files, 0); $sigspath = "sigs/"; unlink($sigspath . $foldername . ".gif/index.php"); rmdir($sigspath . $foldername . ".gif"); //now delete user_id's from database mysql_query("DELETE * FROM users WHERE user_id=$oldusers_users"); mysql_query("DELETE * FROM images WHERE user_id=$oldusers_images"); unset($oldusers_users, $oldusers_images, $oldusers_files, $foldername, $sigspath ); mysql_close($link); Right now it is only returning the first entry, not the entire list that meets the criteria. It does delete that one file though but does not remover the rows from the database. I am sure the database stuff is jacked up I am really new to that part. What am I doing wrong here or is there a better way to do this perhaps Hello,
I want to show checkbox is checked when there is entry of that id in a table in my database.
I have 2 tables page and access_level. I am getting data from page table and displays it in <ul><li> tag with checkbox to select all or only few. After selecting the checkbox, i will store only selected checkbox value in access_level table along with table id. Page link and page name details will be stored in page table.
Now if i want to edit , i should display all the pages which is there in page table and i should also mark checked to those which are already stored in access_level table.
I am using LEFT OUT JOIN, It displays all the pages. But it is not displaying the check mark to those which are already selected.
Here is my code
<?php $s1 = mysql_query("SELECT pages.page_id, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.department, access_level.position, access_level.active FROM pages LEFT OUTER JOIN access_level ON pages.page_id=access_level.page_id WHERE access_level.department=".$department." AND access_level.position=".$position." AND pages.code='sn'") or die(mysql_error()); while($s2 = mysql_fetch_array($s1)) { ?> <tr><td><li><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['page_id']; ?>" <?php if($row['pgid'] === $s2['page_id']) echo 'checked="checked"';?> />here is my pages table pages.JPG 26.55KB 0 downloads access_level access_level.JPG 19.09KB 0 downloads In access_level table i do not have page ids 8 and 9. But i want to display that also from pages table and for 1 to 7 and 10 i should display check mark. How i can achieve this? Please Help |