mclamais Posted June 13, 2008 Share Posted June 13, 2008 So I have a query string I need to work with ?p=2222_1,8621_2,5524_1 or p=[sku]_[quantity],[sku]_[quantity],[sku]_[quantity] I need to extract the values so I can create a little mini-cart for display only What's the best way do I split querty string by the comma, and underscore, and store it so work with it. I'll use the sku's to do a query, (I don't need help here) just he parsing and array stuff. $query1 = "SELECT * FROM products WHERE sku IN (" .$skus. ")"; Thanks Link to comment https://forums.phpfreaks.com/topic/110121-parse-string-and-array-help/ Share on other sites More sharing options...
kenrbnsn Posted June 13, 2008 Share Posted June 13, 2008 Use the expode() function: <?php $skus = array(); $quant = array(); $p = '2222_1,8621_2,5524_1'; foreach (explode(',',$p) as $tmp) list($skus[],$quant[]) = explode('_',$tmp); $query1 = "SELECT * FROM products WHERE sku IN (" . implode(',',$skus) . ")"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/110121-parse-string-and-array-help/#findComment-565141 Share on other sites More sharing options...
MadTechie Posted June 13, 2008 Share Posted June 13, 2008 i would probably do this (was written quickly and on the fly, expect bugs,typos) <?php $item = explode(",", $_GET['p']); foreach($item as $i) { list($iSKU[], $iQty[]) = explode("_", $i); } $SKUs = implode(",",$iSKU[$n]); $query1 = "SELECT * FROM products WHERE sku IN (" $SKUs. ")"; ?> EDIT: LOL well thats sums it up Link to comment https://forums.phpfreaks.com/topic/110121-parse-string-and-array-help/#findComment-565142 Share on other sites More sharing options...
mclamais Posted June 13, 2008 Author Share Posted June 13, 2008 Wow thanks. One more thing, let's say I get prod_title for the database, how can I combine the original data (skus, quants) with the prod_title and display it so that each relates properly. Quantity SKU Product Title 1 2222 Blah, Blah Link to comment https://forums.phpfreaks.com/topic/110121-parse-string-and-array-help/#findComment-565154 Share on other sites More sharing options...
DarkWater Posted June 13, 2008 Share Posted June 13, 2008 Make an auto-incrementing ID column. Link to comment https://forums.phpfreaks.com/topic/110121-parse-string-and-array-help/#findComment-565161 Share on other sites More sharing options...
mclamais Posted June 13, 2008 Author Share Posted June 13, 2008 Make an auto-incrementing ID column. I have that of course, but I was asking how I relate my database results with quantities requested that are only in the array that came from the query string. Link to comment https://forums.phpfreaks.com/topic/110121-parse-string-and-array-help/#findComment-565167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.