Jump to content

Recommended Posts

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

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

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

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

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.