Bravat Posted February 14, 2011 Share Posted February 14, 2011 Here is the while loop: <?php require_once("../includes/initialize.php"); $sql="SELECT * FROM product WHERE product_id IN ("; foreach($_SESSION['cart'] as $id => $value) { $sql.=$id.","; } $sql=substr($sql, 0, -1).") ORDER BY model ASC"; $query=mysql_query($sql); $totalprice=0; while($row=mysql_fetch_array($query)){ $subtotal=$_SESSION['cart'][$row['product_id']]['quantity']*$row['price']; $totalprice+=$subtotal; ?> <tr> <td><?php echo $row['model'] ?></td> <td><?php echo $_SESSION['cart'][$row['product_id']]['quantity'] ?></td> <td><?php echo number_format($row['price'], 2, ',', '.'); ?>din</td> <td><?php $cena = $_SESSION['cart'][$row['product_id']]['quantity']*$row['price']; echo number_format($cena, 2, ',', '.'); ?>din</td> </tr> <?php } ?> How to get data out of the loop? I need it to be same as data echoed (this is the echo result: BFG 225/30 ZR 20 4 21.667,00din 86.668,00din). Quote Link to comment https://forums.phpfreaks.com/topic/227683-get-data-out-of-while-loop/ Share on other sites More sharing options...
Pikachu2000 Posted February 14, 2011 Share Posted February 14, 2011 What do you mean by getting data out of the loop? You can assign values to arrays or variables in the loop and have it available after the loop completes, if that's what you're asking. Quote Link to comment https://forums.phpfreaks.com/topic/227683-get-data-out-of-while-loop/#findComment-1174294 Share on other sites More sharing options...
Bravat Posted February 15, 2011 Author Share Posted February 15, 2011 That the thing i want. I need to mail order to the buyer, and in the while loop is all the data from the cart. I want that data to be subject in the mail function. Quote Link to comment https://forums.phpfreaks.com/topic/227683-get-data-out-of-while-loop/#findComment-1174303 Share on other sites More sharing options...
Ninjakreborn Posted February 15, 2011 Share Posted February 15, 2011 He already explained how. Basically you set a variable ($content for example) and then capture everything your currently echoing into that variable instead ($content .= 'whatever') and then use that variable to setup the mailing, once the while loop is done. Quote Link to comment https://forums.phpfreaks.com/topic/227683-get-data-out-of-while-loop/#findComment-1174390 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.