DarkJamie Posted February 2, 2010 Share Posted February 2, 2010 Hi folks. I'm back with another question on displaying array results. My problem is pretty simple, I just haven't been successful in executing it. I have a page that displays a list of products with checkboxes and prices. The checked items go into an array called "reports". The data is then passed to the selection page, where I wish to display each product description and price based on the ID values from the checkbox array. So what I am asking is how do I display the description and price of each product in the array (and then print a sum of their prices)? here is my code for the selection page. It is incomplets, as I have cleaned out my erroneous code. if (isset($_POST['reports'])) { foreach ($_POST['reports'] as $key => $rid) echo "<h2>Individual Reports</h2>"; echo "<h4>You've selected the following reports:</h4>"; while ($row=mysql_fetch_array($sql_result)) { $id = $row["id"]; $file_number=$row["file_number"]; $filename=$row["filename"]; $description=$row["description"]; $price=$row["price"]; $active=$row["active"]; echo "<table border=0>"; echo "<tr>"; echo "<td width=320px>$description</td>"; echo "<td><b>$price</b></td>"; echo "</tr>"; echo "</table>"; } echo "</table>"; } Link to comment https://forums.phpfreaks.com/topic/190698-display-db-query-results-based-on-values-from-an-array/ Share on other sites More sharing options...
akitchin Posted February 2, 2010 Share Posted February 2, 2010 if you've got all the report IDs in the $_POST['reports'] array, you can collect them into one string and SELECT all of the report info from the db: $rid_list = implode(',', $_POST['reports']); $query = "SELECT * FROM reports WHERE ID IN ($rid_list) ORDER BY whatever"; to get the total price, you can simply add each individual report price to a total as you display them. Link to comment https://forums.phpfreaks.com/topic/190698-display-db-query-results-based-on-values-from-an-array/#findComment-1005699 Share on other sites More sharing options...
DarkJamie Posted February 2, 2010 Author Share Posted February 2, 2010 that is awesome. I originally tried to use the $rid in my sql query, but could only get it to display the last checked product. I will definitely give this a go. Thanks for the fast reply. Link to comment https://forums.phpfreaks.com/topic/190698-display-db-query-results-based-on-values-from-an-array/#findComment-1005708 Share on other sites More sharing options...
DarkJamie Posted February 2, 2010 Author Share Posted February 2, 2010 Thank you Atkichin. Explode was exactly what I needed. Link to comment https://forums.phpfreaks.com/topic/190698-display-db-query-results-based-on-values-from-an-array/#findComment-1005725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.