ImJustBrndn Posted August 21, 2006 Share Posted August 21, 2006 I have a shopping cart set up to push the session (where all the products are stored) into a print and it displays the results like this:Array( [1] => Array ( [ 0] => 1 [1] => 1 ) [3] => Array ( [ 0] => 3 [1] => 2 ) [5] => Array ( [ 0] => 5 [1] => 1 ) [6] => Array ( [ 0] => 6 [1] => 1 ))The inital block in front of the Array is the product id and the last number after the => is the quantity of that product. Is there anything I can route this too or better yet some defining factor I can put in the page before I have it submit them in a email form to display the product name instead of id so for example it says oh hey thats a 6 product id that Trash Cans and then do the quantity the same way. Thanks for the help.B Quote Link to comment Share on other sites More sharing options...
zq29 Posted August 21, 2006 Share Posted August 21, 2006 You'd have to run an SQL query to fetch the name while looping through your array. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 21, 2006 Share Posted August 21, 2006 Assume your session array is called 'cart'[code]<?php$product_ids = array_keys($_SESSION['cart']);$product_$qry "SELECT `prod_id`,`prod_name` FROM `products` WHERE `prod_id` IN (" . implode(',',$product_ids) . ")";$qry = mysql_query($qry);$db_prod = array();while ($row = mysql_fetch_assoc($qry)){ $db_prod['name'][$row['prod_id']] = $row['prod_name'];} ...?>[/code]then as you loop through your session var you simply replace the id with the corresping value in teh $db_prod array.eg 3 would be $db_prod['name'][3] Quote Link to comment 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.