FrankieGee Posted June 12, 2013 Share Posted June 12, 2013 (edited) I am trying to show each checked item in a new row in an html (php) table. Currently, it is working when one selection has been made via a checkbox, but when a new selection is made, the first one is overwritten. I call my Checkboxes like this: echo "<input type=\"checkbox\" rel=\"textbx1\" name=\"$item_no\">$item_no $ihddescr_1</input><br />"; Which gives me a list of items from a selected vendor. I then use this table below, as I will need to show cost, price, etc in a table. echo "<table border ='0' width='100%'><tr><td align='center'><strong><font size='4'><font color='#008301'>Quote Items</font></strong></td></tr></table>"; echo "<table border ='1' width='100%'>"; echo "<th>Item ID</th>"; echo "<th>Description</th>"; echo "<th>QTY</th>"; echo "<th>Sell Price</th>"; echo "<th>Cost</th>"; echo "<th>Prft%</th>"; echo "<th>Prft$</th></tr>"; $quoted = "<td><text id=\"textbx1\"></text></td><td></td><td> </td><td> </td><td> </td><td><input type='text' name='profit' size='6'> </td><td> </td></tr>"; { $cscode=odbc_result($rs,"cscode"); $csname=odbc_result($rs,"csname"); $item_no=odbc_result($rs,"item_no"); $order_date=odbc_result($rs,"order_date"); $order_date2 = date( "m-d-Y", strtotime( $order_date ) );*/ $getQuote=array("$item_no \"\n\""); foreach ($getQuote as $item) $item = "$quoted"; { echo $quoted; } odbc_close($conn); echo "</table>"; I should also add that I am using Javascript to populate the rows. <script type="text/javascript"> $(window).load(function(){ $(document).ready(function() { $("input[type=checkbox]").click(function() { if ($(this).is(':checked')) $('#textbx1').html($('#textbx1').val() + $(this).attr('name') + "\n"); else { var text = $('#textbx1').val(); text = text.replace($(this).attr('name') + "\n" ,""); $('#textbx1').html(text); } }); }) }); </script> Any help what-so-ever would be appreciated. Thanks. Edited June 12, 2013 by FrankieGee Quote Link to comment https://forums.phpfreaks.com/topic/279070-new-rows-not-working-overwriting-last-entry-in-cell/ Share on other sites More sharing options...
Barand Posted June 12, 2013 Share Posted June 12, 2013 Give your checkboxes a name attribute ending with "[]" eg name=\"$item_no[]\" All selected values will then be posted in an array Quote Link to comment https://forums.phpfreaks.com/topic/279070-new-rows-not-working-overwriting-last-entry-in-cell/#findComment-1435544 Share on other sites More sharing options...
FrankieGee Posted June 12, 2013 Author Share Posted June 12, 2013 Thank you for the reply, but I have tried this one and get an error: Parse error: syntax error, unexpected ']', expecting T_STRING or T_VARIABLE or T_NUM_STRING Quote Link to comment https://forums.phpfreaks.com/topic/279070-new-rows-not-working-overwriting-last-entry-in-cell/#findComment-1435547 Share on other sites More sharing options...
FrankieGee Posted June 12, 2013 Author Share Posted June 12, 2013 I have attached the entire file. There are many lines that have been commented out, as I am still experimenting with this.salesquote.php Quote Link to comment https://forums.phpfreaks.com/topic/279070-new-rows-not-working-overwriting-last-entry-in-cell/#findComment-1435550 Share on other sites More sharing options...
Barand Posted June 12, 2013 Share Posted June 12, 2013 Sorry, I just copied your name= bit and didn't spot the $ in the name. Try echo "<input type=\"checkbox\" name=\"item_no[]\" value=\"$item_no\" />$item_no $ihddescr_1<br />"; Your selected item numbers will be in the array $_POST['item_no'] Quote Link to comment https://forums.phpfreaks.com/topic/279070-new-rows-not-working-overwriting-last-entry-in-cell/#findComment-1435553 Share on other sites More sharing options...
rwhite35 Posted June 12, 2013 Share Posted June 12, 2013 (edited) Hi Frank, Taking a look at your file, couple suggestions that might help you debug (there's a few). Enable Firebug on your Firefox browser, click the Consule tab and re-run your script. You'll discover a few Javascript errors. For PHP you can setup an error log that will wright your custom errors out to a text file. I like to do this wherever I'm trying to visualize whats going on under the hood. The following code is how you would use this: <?php //log custom error messages $log_path = "/path/to/your/log/file/dev_log_messages.txt"; $log_tstamp = date('Y-m-d G:H:s',time()); //then later in your code blocks $someVariable = "Test String"; error_log($log_tstamp." the test string is ".$someVariable."\n",3,$log_path); Using this technique will help you identify values or result that don't display to the browser window, but are critical to the process success. Couple overall thoughts, ideally, you want your PHP code block above your HTML code block. Specially since you are using sessions, the PHP session header needs sent before anything else. <?php session_start(); //some php code ?> <html> //some javascript and html </html> Sorry this doesn't answer your question directly, but in the long run, it will help you code better and faster. Edited June 12, 2013 by rwhite35 Quote Link to comment https://forums.phpfreaks.com/topic/279070-new-rows-not-working-overwriting-last-entry-in-cell/#findComment-1435556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.