PHP - Checkbox Select In A Loop
Hi , i am running a loop where i show 10 categories to edit , now i have values from previous loop of those categories and i wants checkbox to be selected of all those categories whcih i have in my loop but it only select one here is my code:
<?php //$category_links is array which contains 3 values should be checked, there are total 10 categories $category_links = array(2,5,7); $query = $db->query("SELECT * from categories ORDER BY id"); while($row = $db->fetchArray($query)): ?> <input type="checkbox" name="categories[]" value="<?php echo $row['id']; ?>" > <?php echo $row['name']; endwhile; } i tried with for loop but it only select one category not other <?php //$category_links is array which contains 3 values should be checked $category_links = array(2,5,7); $query = $db->query("SELECT * from categories ORDER BY id"); for($i = 0;$i <= count($category_links);$i++) { while($row = $db->fetchArray($query)): ?> <input type="checkbox" name="categories[]" value="<?php echo $row['id']; ?>" <?php if($row['id'] == $category_links[$i]) { echo "checked=checked"; }?> ><?php echo $row['name']; ?> <?php endwhile; } Thanks for help Similar TutorialsHow do I post the values that are in a while loop and add them to mysql table? <form action="Test_Completed.php" method="post"> include '../Database/take_an_exam.php'; $intNumber = 1; while($info = mysql_fetch_array( $sql )) { echo "$intNumber, {$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; $intNumber++; } ?> <input type="submit" value="submit"/> </body> </html> </body> </html> Hi all: I start an application in PHP and SQL Server for a company car and I need some recommendations. The application tracked him to the maintenance of the cars. On one side are the car brands (Ford, Chevrolet, etc.) with the relevant goods and associated services. A relationship many-to-many. On the other hand, the executives (stage 1) enter the customer associated with their cars and the corresponding products and services. The customer goes to the mechanic who performs the action (step 2) and finally counter that the collection (step 3). My main problem is how to link Client - Automobile - Services in the first form. Enter the name and telephone number after a multi-select will select the brand and asynchronously checkbox must be loaded in all services and check the corresponding to that mark. I find it difficult to incorporate all the links on the form. Appreciate design recommendations database (customer table) and how to assemble the form. Maybe some of you made any similar application or know a reference. Finally thank you in advance for the time can provide for review this post. Hi All, I've a loop which lists a series of options as checkboxes. What I'd like to do is set 1 as a default. But I've no idea how to do it!? Here's the code: <?php $i = 0; ?> <?php if ( bp_has_groups() ) : while ( bp_groups() ) : bp_the_group(); ?> <input type="checkbox" id="field_reg_groups_<?php echo $i; ?>" name="field_reg_groups[]" value="<?php bp_group_id(); ?>" /><?php bp_group_name(); ?> <?php } ?> <?php $i++; ?> Any help is much appreciated TIA Hi everyone, I need to retain the checkbox selections after the form is submitted, but I'm stuck and wondering if anyone can offer some assistance? Thank you. <?php $categories = mysqli_query($db,'SELECT id, category FROM category'); if (!$categories) { exit('<p>Unable to obtain category list from the database.</p>'); } // Check if there are any categories and if so, list them. if (mysqli_num_rows($categories) != 0){ echo '<p>Select the related categories:<br />'; while ($category = mysqli_fetch_array($categories)) { $categoryid = $category['id']; $categoryname = htmlspecialchars($category['category']); $checked= ($category['id']==$categories) ? ' checked="checked"' : ''; echo '<input type="checkbox" name="categories[]" value="'.$categoryid.'" '.$checked.' > '.$categoryname.' <br/>'; } } ?>
i have this code: foreach($product_names as $product_row) { ?> <tr> <td > </td><td width='200px'><?php echo $product_row->getName(); ?></td> <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" /></td> <td width='200px'><input type="checkbox" name="text[]" value="<?php echo $product_row->getId();?>" /></td> </tr> <?php } ?> </table> <table> <tr> <td> <input type='hidden' name='submit' value='Submit'> <?php if ( (isset($graphic)) || (isset($text) )) { echo "checkboxes checked"; //show submit button } else { //hide submit botton and echo "no boxes check"; } ?> </td> </tr> </table> so if i want to loop through grapic[] with the code: line 36 $graphics_selected = $_POST['graphic']; line 37 foreach($graphics_selected as $val) { if there is something in array(thus any checkbox is checked) enable submit button else if no checkboxes are checked disable submit button } i get errors: Notice: Undefined index: graphic in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 36 Warning: Invalid argument supplied for foreach() in /home/helloises/svn_wappool/apps/lpmanager/modules/doc/templates/productSuccess.php on line 37 please help???? Howdy everyone, please i need help changing a php coded form from a checkbox to a select menu. Here's the form. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" > <table class="dtable2"> <tr><th colspan="5">Enter a domain name:</th></tr> <tr><td colspan="5"><center>www.<input name="domain" type="text" size="35" /></center></td></tr> <tr><th colspan="5">Select an extension:</th></tr> <tr> <?php $i = 0; foreach ($this->serverList as $value) { if ($value['check'] == true) $checked=" checked "; else $checked = " "; echo '<td><input type="checkbox" name="top_'.$value['top'].'"'.$checked.'/>.'.$value['top'].'</td>'; $i++; if ($i > 4) { $i = 0; echo '</tr><tr>'; } } ?> </tr> </table> <center><input type="submit" name="submitBtn" class="sbtn" value="Check" /></center> </form> <?php I'll really appreciate your help. Or something like that... I am not sure how to put this.. Anyway, I'll just get started with explaining my problem. I have an admin-page in which you can delete the comments given on blogs, using checkboxes and clicking on a button with the value 'verwijderenSubmit'. The deletion part works just fine, nothing wrong. However, I also want to be able to EDIT the comments with an other button called 'bewerkenSubmit', using the same checkboxes that I use for deletion. Selecting the right CID (CommentID) is no problem, because that works the same as the deletion-part, but selecting the right textarea to update into the database is the problem... I uploaded a file here with the whole code: http://dhost.info/ddfs/myproblem.html I escaped the textarea within with square brackets, because otherwise the whole textarea would screw up.. I also added <!-- RELEVANT CODE --> to select the parts that I need to change. Well, I hope you understand my problem and can help. Hi all, I have a situation where I need to remember what check boxes where checked over pagination, I have managed to do this via the use of this: http://jamesfunk.com/wordpress/?p=65 The problem is that as the code stood: Code: [Select] <input type="checkbox" name="compare" value="<?php echo $list['jobseeker_id'];?>" class="remember_cb"/> It was treating one ticked checkbox as them all because they all have the same name and are in the a while loop! I countered this by changing the code to: Code: [Select] <input type="checkbox" name="compare<?php echo $list['jobseeker_id']?>" value="<?php echo $list['jobseeker_id'];?>" class="remember_cb"/> Which effectively now makes the checkbox name unique... i.e. compare{id}. The problem with this is that I can now no longer process it. This is my processing code: $jobseekers = $_POST['compare']; $i = 0; for($i; $i<count($jobseekers); $i++){ $query = "SELECT * FROM jobseekers WHERE jobseeker_id = '$jobseekers[$i]'"; $result = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_array($result)) { // Spit out the required data } } As you can see I am trying to get the data from $_POST['compare'], which will obviously now be blank as I have had to make the name unique.... the trouble is I'm not sure how to actually process this. Can anyone help me out here? any help or advice would be greatly appreciated! many thanks, Greens85 I have 2 question, which are related to each other. They are about my current school project. Which I have been really stupid for, I took it too slow and thought I had enough time. But no, I had to do almost my whole project in the last 3 weeks and sunday is the deadline. I have a couple pages to make left, which one of them is the hardest one and I have the 2 questions about it. Question 1. I have to make a invoice with 4 different prices, divided over 3 tables in my mysql. Let me sum up the tables. Products Productsid - productprice Productrule Productruleid - amount - productid - maintainanceid Maintainance Maintainanceid - price I need to show the price The price of each product The amount * productprice The amount * productprice + price All in a table, it mustn't be edited, so it not in a form. I know I have to use a SQL select sum for it, but I have never used it, and my querys always fail in the first place I used a for and while loop to choose the amount of and the name of products for the mechanic page. There was a max of 5 products to select, just to keep it easier. If I would only pick 2, it wouldn send something empty to the database and it wasn't required. My teacher helped me with that and it works. So then we come to question 2, can I use that in a table, instead of a drop down menu, which I used at the mechanic page. This is the PHP code: Code: [Select] for($i=1;$i<=5;$i++) { if(($_POST['aantal'.$i] != "") AND ($_POST['product'.$i] != "")) { $query3 = mysql_query ("INSERT INTO onderdeelregel SET aantal='".$_POST['aantal'.$i]."', onderdelenid='".$_POST['product'.$i]."', werkzaamhedenid='".$werkzaamhedenid."'"); } } And the HTML: Code: [Select] <table border="0"> <tr> <th>Aantal</th> <th>Product</th> <tr> <!-- START BLOCK : PRODUCT_REGEL --> <tr> <td> <input class="wijzigInput" name="aantal{NUMMER}" id="aantal" type="text" maxlength="2" size="2" /></td> <td> <select name="product{NUMMER}"> <option selected="selected" class="wijzigOption" value=""></option> <!-- START BLOCK : PRODUCT_REGEL_OPTION --> <option class="wijzigOption" value="{PRODUCT_REGEL_WAARDE}">{PRODUCT_REGEL_NAAM}</option> <!-- END BLOCK : PRODUCT_REGEL_OPTION --> </select> </td> </tr> <!-- END BLOCK : PRODUCT_REGEL --> </table> Oh I didn't used a while loop there, but I know I have to use it in the customer page. I know this isn't going to work on my own, and I haven't got much time left. I would really appreciate it if anyone could give me some code, or atleast a start of the sql select sum and the for and while loop in a table. I know I have add other stuff to the invoice, but that isn't hard, so with this I should be able to do it and finish my project in time. I usually don't like that, I want to learn it myself, but time is very little right now Oh and sorry for the Dutch in my code. Please help me, I don't want to stress out and fail it. School is very important to me and I hate myself for taking it so slow. Thanks a lot Chris Hey guys there is probably a simple fix to this but i am just not seeing it ... Im createing a form that has error catching and self submitting valuse. I am trying to use a for loop to create all of the values and if the form is returned with an error then the correct values will still be filled out but i cant seem to get this loop to work. Every time i submit the form it doesnt matter what option i select it always comes back with the last one in the list or 30 in this case. the problem code is below.. Any help would be appreciated. Code: [Select] <?php for($i=1; $i<=30; $i++){ echo'<option value="'.$i.'"'; if(isset($_POST['petsAge'])== $i){ echo ' selected="selected"';} echo '>'.$i.'</option>'; } ?> hi i am in situation to display input box along with select option , here is my code <?php $run= $dbc->db("SELECT * FROM `table` WHERE `id`='$id'"); ?> <select name="service"> <?php while ($result = mysql_fetch_array($run)) { ?> <option value="<?php echo $result['id'] ; ?>"><?php echo $result['service'] ; ?></option> <?php // This is problem i need to get this as hidden field but it breaks my select options. ?> <input type="hidden" value="<?php echo $result['data'] ; ?>" name="data" /> <?php } ?> </select> so here i am stuck <input type="hidden" value="<?php echo $result['id'] ; ?>" name="data" /> when i repeat in while loop it breaks options box and display other options without in select box. any help please thanks I want to make a table for each paddler_id (Field) which exists into pushup Database My code for paddler_id = 1 is require "../sql.php"; $result = mysql_query("EXPLAIN pushup"); $r = mysql_query("SELECT * FROM paddlerinfo t1 LEFT JOIN pushup t2 on t2.paddler_id=t1.id LEFT JOIN practicedate t3 on t3.practice=t2.practice_id ORDER BY t1.firstname ASC "); $r1 = mysql_query("SELECT * FROM pushup where paddler_id =1 ORDER BY practice_id ASC "); echo "<table width='30%' border='1' cellpadding='0' cellspacing='0' style='font-family: monospace'>"; echo "<tr>"; echo "<td>DATE</td>"; while ($row = mysql_fetch_array($result)) { if (in_array($row["Field"], array("paddler_id", "practice_id", "p_id"))) continue; echo "<td>",($row["Field"]), "</td>"; } echo "</tr>"; while (($data = mysql_fetch_array($r1, MYSQL_ASSOC)) !== FALSE) { unset($data["p_id"],$data["paddler_id"]); echo "<tr>"; foreach ($data as $k => $v) { echo "<td>"; echo"$v"; echo "</td>"; } echo "</tr>"; } echo "</table>"; mysql_free_result($result); mysql_free_result($r); mysql_free_result($r1); mysql_close(); The problem is on line $r1 = mysql_query("SELECT * FROM pushup where paddler_id =1 ORDER BY practice_id ASC "); I want to put something which makes it paddler_id = X where x = 2,3,4,5... and x exists in database and do not print twice the x (because that database may have rows where x = same id How do i do that?? Is it possible to have a loop inside a mysql select statement? If yes, can someone please give me an idea. Hi.. I need to save data from a while loop and data from select option, Now I encountered that using my query I only save is the last part of my while loop and also the data that I choose in select option did not save. here is my code: Code: [Select] <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sr_date = $_POST['sr_date']; $sr_number = $_POST['sr_number']; $Items = $_POST['Items']; $SubItems = $_POST['SubItems']; $ItemCode = $_POST['ItemCode']; $DemandedQty = $_POST['DemandedQty']; $UoM = $_POST['UoM']; $Class = $_POST['Class']; $Description = $_POST['Description']; $BINLocation = $_POST['BINLocation']; $RequestedBy = $_POST['RequestedBy']; $ApprovedBy = $_POST['ApprovedBy']; $ReceivedBy = $_POST['ReceivedBy']; $IssuedBy = $_POST['IssuedBy']; $sql = "INSERT INTO stock_requisition (sr_date, sr_number, Items, SubItems, ItemCode, DemandedQty, UoM, Class, Description, BINLocation, RequestedBy, ApprovedBy, ReceivedBy, IssuedBy) VALUES ('$sr_date', '$sr_number', '$Items', '$SubItems', '$ItemCode', '$DemandedQty', '$UoM', '$Class', '$Description', '$BINLocation', '$RequestedBy', '$ApprovedBy', '$ReceivedBy', '$IssuedBy') ON DUPLICATE KEY UPDATE sr_date = '$sr_date', sr_number = '$sr_number', Items = '$Items', SubItems = '$SubItems', ItemCode = '$ItemCode', DemandedQty = '$DemandedQty', UoM = '$UoM', Class = '$Class', Description = '$Description', BINLocation = '$BINLocation', RequestedBy = '$RequestedBy', ApprovedBy = '$ApprovedBy', ReceivedBy = '$ReceivedBy', IssuedBy = '$IssuedBy'"; $result = mysql_query($sql, $con); $sql = "SELECT sr_number FROM stock_requisition ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Stock Requisition</title> <head> <style type="text/css"> #ddcolortabs{ margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs a span{ float:none; } #ddcolortabs a:hover{ background-color: #678b3f; } #ddcolortabs a:hover span{ background-color: #678b3f ; } #ddcolortabs #current a, #ddcolortabs #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style type="text/css"> #ddcolortabs1{ position: relative; top: 10px; margin-left: 2px; padding: 0; width: 100%; background: transparent; voice-family: "\"}\""; voice-family: inherit; padding-left: 2px; } #ddcolortabs1 ul{ font: bold 12px Arial, Verdana, sans-serif; margin:0; padding:0; list-style:none; } #ddcolortabs1 li{ display:inline; margin:0 2px 0 0; padding:0; text-transform:uppercase; } #ddcolortabs1 a{ float:left; color: white; background: #8cb85c url(layout_image/color_tabs_left.gif) no-repeat left top; margin:2px 2px 0 0; padding:0px 0 1px 3px; text-decoration:none; letter-spacing: 1px; } #ddcolortabs1 a span{ float:right; display:block; /*background: transparent url(layout_image/color_tabs_right.gif) no-repeat right top;*/ padding:6px 9px 2px 6px; } #ddcolortabs1 a span{ float:none; } #ddcolortabs1 a:hover{ background-color: #678b3f; } #ddcolortabs1 a:hover span{ background-color: #678b3f ; } #ddcolortabs1 #current a, #ddcolortabs1 #current span{ /*currently selected tab*/ background-color: #678b3f; } </style> <style> #SR_date{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #SR_number{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 270px; width: auto; height: auto; float: left; top : 10px; } table { margin: 10px; font-family: Arial, Helvetica, sans-serif; font-size: .9em; border: 1px solid #DDD; width: auto; } th { font-family: Arial, Helvetica, sans-serif; font-size: .7em; background: #694; color: #FFF; padding: 2px 6px; border-collapse: separate; border: 1px solid #000; } td { font-family: Arial, Helvetica, sans-serif; font-size: .7em; border: 1px solid #DDD; text-align: left; } #RequestedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } #ApprovedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #ReceivedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; } #IssuedBy{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 15px; width: auto; height: auto; float: left; top : 10px; margin-right: 120px; } #save_btn{ position: relative;; font-family: Arial, Helvetica, sans-serif; font-size: .8em; margin-left: 10px; top: 10px; } </style> <script type="text/javascript"> function save_sr(){ var sr_date = document.getElementById("sr_date").value; var sr_number = document.getElementById("sr_number").value; var Items = document.getElementById("Items").value; var SubItems = document.getElementById("SubItems").value; var ItemCode = document.getElementById("ItemCode").value; var DemandedQty = document.getElementById("DemandedQty").value; var UoM = document.getElementById("UoM").value; var Class = document.getElementById("Class").value; var Description = document.getElementById("Description").value; var BINLocation = document.getElementById("BINLocation").value; var RequestedBy = document.getElementById("RequestedBy").value; var ApprovedBy = document.getElementById("ApprovedBy").value; var ReceivedBy = document.getElementById("ReceivedBy").value; var IssuedBy = document.getElementById("IssuedBy").value; document.stock_requisition.action="StockRequisitionSave.php?sr_date="+sr_date+"&sr_number="+sr_number+"&Items="+Items+ "&SubItems="+SubItems+"&ItemCode="+ItemCode+"&DemandedQty="+DemandedQty+"&UoM="+UoM+"&Class="+Class+"&Description="+ Description+"&BINLocation="+BINLocation+"&RequestedBy="+RequestedBy+"&ApprovedBy="+ApprovedBy+"&ReceivedBy="+ReceivedBy+ "&IssuedBy="+IssuedBy; document.stock_requisition.submit(); alert("Stock Requisition data save."); window.location = "StockRequisition.php"; } </script> </head> <body> <form name="stock_requisition" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="ddcolortabs"> <ul> <li> <a href="ParameterSettings.php" title="Parameter Settings"><span>Parameter Settings</span></a></li> <li style="margin-left: 1px"><a href="kanban_report.php" title="WIP Report"><span>Wip Report</span></a></li> <li id="current"><a href="StockRequisition.php" title="WMS RM"><span>WMS RM</span></a></li> </ul> </div> <div id="ddcolortabs1"> <ul> <li><a href="ReceivingMaterials.php" title="Receiving Materials"><span>Receiving Materials</span></a></li> <li><a href="Shelving.php" title="Shelving"><span>Shelving</span></a></li> <li id="current"><a href="StockRequisition.php" title="Stock Requisition"><span>Stock Requisition</span></a></li> </ul> </div> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>SR# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="10" readonly="readonly" style="font-weight: bold; border: none;"> <br/> </div> <div> <table> <thead> <th>Items</th> <th>Sub Items</th> <th>Item Code</th> <th>Demanded Qty</th> <th>UoM</th> <th>Class</th> <th>Description</th> <th>BIN Location</th> </thead> <?php $sql = "SELECT DISTINCT Items FROM bom_subitems ORDER BY Items"; $res_bom = mysql_query($sql, $con); while($row = mysql_fetch_assoc($res_bom)){ $Items = $row['Items']; echo "<tr> <td style='border: none;font-weight: bold;'> <input type='name' value='$row[Items]' name='Items' id='Items' readonly = 'readonly' style = 'border:none;width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='5'></td> </tr>"; $sql = "SELECT SubItems, ItemCode, UoM, Class, Description, BINLocation FROM bom_subitems WHERE Items = '$row[Items]' ORDER BY Items"or die(mysql_error()); $res_sub = mysql_query($sql, $con); while($row_sub = mysql_fetch_assoc($res_sub)){ echo "<tr> <td style='border: none;'> </td> <td style='border: none;'> <input type='text' name='SubItems' value='$row_sub[SubItems]' id='SubItems' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='ItemCode' value='$row_sub[ItemCode]' id='ItemCode' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'><center><input type='text' name='DemandedQty' id='DemandedQty' value='' size='7'></center></td> <td style='border: none;' size='3'> <input type='text' name='UoM' value='$row_sub[UoM]' id='UoM' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='3'></td> <td style='border: none;'> <input type='text' name='Class' value='$row_sub[Class]' id='Class' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='Description' value='$row_sub[Description]' id='Description' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> <td style='border: none;'> <input type='text' name='BINLocation' value='$row_sub[BINLocation]' id='BINLocation' readonly='readonly' style='border:none; width:auto;font-family: Arial, Helvetica, sans-serif;font-size: 1em;' size='10'></td> </tr>"; } } ?> </table> </div> <div id='RequestedBy'> <label>Requested By:</label> <select name="Requested_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ApprovedBy'> <label>Approved By:</label> <select name="Approved_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBBB'>BBBBBBBBB</option> <option name='CCCCCCCCCC'>CCCCCCCCCC</option> </select> </div> <div id='ReceivedBy'> <label>Received By:</label> <select name="Received_By"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id='IssuedBy'> <label>Issued By:</label> <select name="Issued BY"> <option name='None'>Select</option> <option name='AAAAAAAAA'>AAAAAAAAA</option> <option name='BBBBBBBB'>BBBBBBBB</option> <option name='CCCCCCCC'>CCCCCCCC</option> </select> </div> <div id="save_btn"> <input type="button" name="button" value="save" onclick="save_sr()"> </div> </body> </html> I also I attach the display data. Thank you Hey.
So the issue I'm having is consecutive loops on semi-large arrays, over and over. Consider this array:
$firstArray = array( 'row1' => array( 'dates' => array( '2014-01-01' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-02' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-03' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-04' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-05' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-06' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-01-07' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), ) ), 'row2' => array( 'dates' => array( '2014-02-01' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-02' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-03' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-04' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-05' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-06' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-07' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-08' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), '2014-02-09' => array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3', 'key4' => 'value4', 'key5' => 'value5', 'key6' => 'value6', 'key7' => 'value7', 'key8' => 'value8', 'key9' => 'value9', 'key10' => 'value10'), ) ) );Originally the data comes from ~2-3 database tables, of course. But to ilustrate the point, this is how the main array looks like. This array usually contains anywhere between 10-50 rows, each row containing at least 10 dates, with 10 key/values each. And after setting up all the data, it needs to be processed. Currently this is how a friend of mine did it.. $placeDataHere = array(); foreach($firstArray as $key => $dates) { foreach($dates as $date => $values) { foreach($values as $key => $value) { $placeDataHere['DV_' . $date]['SM_' . $key] = 'KS_' . $value; //Followed by another ~50-70 lines of processing the 3 loop's data.. ... ... .... .... .... .... .... .... } } }Obviously this isn't good practise, but we can't seem to figure out a better way of doing it, since both the data and the loops are horribly nested. This loop and setup of $firstArray is run anywhere between 10-20 times/request, due to amount of users we wish to process. So, the result is that this code can take up to over 2-3 minutes to complete, which isn't really optimal performance. In short my question is, are there any better methods of handling this with the data setup we currently have? what Im basically trying to do is just like a phpmyadmin function... you select rows you want to update with a checkbox and then it takes you to a page where the rows that are clicked are shown in forms so that you can view and edit info in them... and then have 1 submit button to update them all at once. hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks Below is my output on the browser: Student: Kevin Smith (u0867587) Course: INFO101 - Bsc Information Communication Technology Course Mark 70 Grade Year: 3 Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B Session: AAB Session Mark: 72 Session Weight Contribution 20% Session: AAE Session Mark: 67 Session Weight Contribution 40% Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B Session: AAD Session Mark: 61 Session Weight Contribution 50% Now where it says course mark above it says 70. This is incorrect as it should be 65 (The average between the module marks percentage should be 65 in the example above) but for some stange reason I can get the answer 65. I have a variable called $courseMark and that does the calculation. Now if the $courseMark is echo outside the where loop, then it will equal 65 but if it is put in while loop where I want the variable to be displayed, then it adds up to 70. Why does it do this. Below is the code: Code: [Select] $sessionMark = 0; $sessionWeight = 0; $courseMark = 0; $output = ""; $studentId = false; $courseId = false; $moduleId = false; while ($row = mysql_fetch_array($result)) { $sessionMark += round($row['Mark'] / 100 * $row['SessionWeight']); $sessionWeight += ($row['SessionWeight']); $courseMark = ($sessionMark / $sessionWeight * 100); if($studentId != $row['StudentUsername']) { //Student has changed $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})\n"; } if($courseId != $row['CourseId']) { //Course has changed $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong>" round($courseMark) "<strong>Grade</strong> <br><strong>Year:</strong> {$row['Year']}</p>\n"; } if($moduleId != $row['ModuleId']) { //Module has changed if(isset($sessionsAry)) //Don't run function for first record { //Get output for last module and sessions $output .= outputModule($moduleId, $moduleName, $sessionsAry); } //Reset sessions data array and Set values for new module $sessionsAry = array(); $moduleId = $row['ModuleId']; $moduleName = $row['ModuleName']; } //Add session data to array for current module $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']); } //Get output for last module $output .= outputModule($moduleId, $moduleName, $sessionsAry); //Display the output echo $output; I think the problem is that it is outputting the answer of the calculation only for the first session mark. How in the while loop can I do it so it doesn't display it for the first mark only but for all the session marks so that it ends up showing the correct answer 65 and not 72? Hey guys, Got another question im hoping someone can help me with. I have a foreach loop (for use in a mysql query): foreach ($interests as $interest) { $query .= "($id, $interest), "; } problem is i do not want the comma(,) in the last loop. Is there some kinda of function i can use so it does not insert it on last loop? Or should i just use a for loop with a nested if loop? something like ; for($i=0; $i < count($interests); $i++){ $query .= "($id, '$interests[$i]')"; if($i + 1 < count($interests)) { $query .= ", "; } } Cheers guys I am working to echo the results in a while or for loop... Both of my sample codes work, but the results are wrong! The while loop ONLY echos a result IF the first record in the postings table matches the id passed (does not display a result unless the first record has a match) The if loop displays ALL listings with the same name (counts them all) so there are no unique listings! <?php $posts_by_city_sql = "SELECT * FROM postings WHERE id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); /* While Loop */ while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } /* For Loop */ $posts_by_city_row = mysqli_fetch_array($posts_by_city_results); for ($i=0; $i<sizeof($posts_by_city_row); $i++) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } ?> Results with for loop (there are 7 total unique book names, but it's just counting the first match on id 7 times like below): AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners AJAX for Beginners |