Topic: PHP explode/implode (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=32106" title="Pages that link to Topic: PHP explode/implode (Page 1 of 1)" rel="nofollow" >Topic: PHP explode/implode <span class="small">(Page 1 of 1)</span>\

 
Ensellitis
Paranoid (IV) Inmate

From: Kansas City, MO , USA
Insane since: Feb 2002

IP logged posted posted 01-10-2011 22:17 Edit Quote

Maybe I just haven slept for awhile... But for the life of me, I can't figure out this problem...

I have a DB that stores quantity like this: "NM:10 M:31 G: 26"

I'm trying to make it so if someone submits something to the database thats already there, it adds to the quantity...

i.e.
$_POST['cond'] = M;
$_POST['qty'] = 10;

So "NM:10 M:31 G: 26" needs to become "NM:10 M:41 G: 26" and then update the mysql database.

I know its a whole explode/implode thing... But exploding it, adding the proper quantities, and then sending it back to the database seems to have me stupified...

Tyberius Prime
Maniac (V) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

IP logged posted posted 01-10-2011 22:46 Edit Quote
code:
$new = array();
foreach (explode($old) as $keyvalue)
{
 $temp = explode($keyvalue, ":");
 if ($temp[0] == $_POST['cond'])
     $temp[1] += int($_POST['qty']);
  $new[] = $temp[0] . ':' . $temp[1];
}
$new = implode($new, " ");



completly untested, and it's been years since i've written any php...

good luck,
so long,

->Tyberius Prime



Post Reply
 
Your User Name:
Your Password:
Login Options: Remember Me On This Computer
 
Your Text:
Loading...
Options: Show Signature
Enable Slimies
Enable Linkwords

« BackwardsOnwards »

Show Forum Drop Down Menu