Closed Thread Icon

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

 
Ensellitis
Paranoid (IV) Inmate

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

posted posted 01-10-2011 22:17

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

posted posted 01-10-2011 22:46
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

« BackwardsOnwards »

Show Forum Drop Down Menu