Jump to content

display db query results based on values from an array


DarkJamie

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.