Guest Posted March 30, 2006 Posted March 30, 2006 Hi, I would be very grateful for anyone's help on this! I have a php script that displays data from a SQL database in rows E.G: Name - Address - Age - Height - Weight - etc - [ ] (& a checkbox) it successfully displays the data in rows, with a checkbox on the end. I would like to be able to tick some checkboxes and then post only 'that' data to a new page this is the code that i have on that page: <form name="form" method="post" action="print.php"> $query = "SELECT * FROM database where `field` = '$value' ORDER BY id desc"; $result = mysql_query($query) or die("Query failed"); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { foreach ($line as $col_value) { $x++; if ($x == 1) { $id = $col_value; } if ($x == 2) { $name = $col_value; } if ($x == 3) { $age = $col_value; } etc... } print "<table><tr>"; print "<td>$name</td>"; print "<td>$age</td>"; print "<td valign=top><input type=text name=id[] multiple value=$id>"; print "<input type=checkbox name=print[] multiple></td>"; print "</tr>\n"; $x = 0; } <input type="submit" value="Print" name="form"> </form> I understand that it builds the data into an array, but im stuck, as to how you then display the array on the new page. i did try this and it worked: $_POST['id'][0],$_POST['print'][0] $_POST['id'][1],$_POST['print'][1] $_POST['id'][2],$_POST['print'][2] $_POST['id'][3],$_POST['print'][3] but what if i have a 100 rows and i select 100 rows, that would mean i would have to repeat the above code 100 times. so really what i require is, if 30 rows are posted to the new page, then the ID of the 30 rows is grabbed and then put through a new loop, to display the new data. any help very much appricated!!! Thanks Dave!
dynamoeffects Posted March 30, 2006 Posted March 30, 2006 for ($x = 0; $x <sizeof($_POST['id']); $x++) { echo $_POST['id'][$x] . ' : ' . $_POST['print'][$x] . '<br>'; } Please use the forums for support! I am happy to help you here, but I am unable to offer free technical support over instant messenger or e-mail.
Jack_mcs Posted March 30, 2006 Posted March 30, 2006 You need to loop through the array and display each item. Many contributions, and even the code in the shop, uses this method. You just need to find where it does that and study the code. For example, in admin->Reports, it lists all of the customers and what they bought or on the index page (using the code from includes/modules/product_listing.php), all products for a category are displayed. Jack Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
Recommended Posts
Archived
This topic is now archived and is closed to further replies.