Jump to content

osaka73

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

osaka73's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I think I got what I needed from your help. But I'm sure I probably took an unnecessary step in the process. Here is what I have now: $cart = $_SESSION['cart']; $items = explode(',',$cart); $qty = array(); foreach ($items as $itemid => $item) { $qty[$item] = $qty[$item] + 1; } $qty = array_unique($qty); foreach ($qty as $id => $quantity) { echo "ID: $id Quantity: $quantity<br />\n"; } And that outputs: ID: 1 - Quantity: 2 ID: 4 - Quantity: 10 I can work with this now and get what I need done. But if I have taken an unnecessary step, would someone mind correcting me? Thanks!
  2. You probably are reading it correctly, but I am still stuck. My thoughts were that if I had an array such as: Array ( [2] => 5 [4] => 8 ) I could then do queries to get the product info on the ids for 2 and 4, and multiple the price from the database by the values for [2] and [4]. Could you give me a little more help on how I might do that? I'll keep working with what you showed me (in the meantime), to see if I can work it out.
  3. I need to assign unknown array keys and their values to strings. The code I am using is: $cart = $_SESSION['cart']; $items = explode(',',$cart); $qty = array(); foreach ($items as $item) { $qty[$item] = $qty[$item] + 1; } print_r($qty); The keys change and are not ordered. I do not know what the key or it's value may be. So as an example, I might have: Array ( [2] => 5 [4] => 8 ) or in a different scenario, I might have: Array ( [1] => 6 ) What those numbers represent is a product id (the key), and the quantity (the value of the key). Can someone help me to assign these to a string? I have been reading all morning, and not making any progress. Thank you!
  4. so it was super easy... I know. $xml = simplexml_load_file("http://lyrics.wikia.com/api.php?artist={$lyric_artist}&song={$lyric_song}&fmt=xml"); $lyric=$xml->lyrics; echo $lyric; I guess that's why they call it simpleXML.
  5. Hi, My script is pretty simple: $xml = simplexml_load_file("http://lyrics.wikia.com/api.php?artist={$lyric_artist}&song={$lyric_song}&fmt=xml"); foreach( $xml as $element ) { print_r( $element ); } Of course those $strings are defined. So the output of that is: SimpleXMLElement Object ( [0] => The Beatles ) SimpleXMLElement Object ( [0] => Let It Be ) SimpleXMLElement Object ( [0] => When I find myself in times of trouble Mother Mary comes to me Speaking words of wisdom Let it be And in my hour of darkness She is standing right in front of me Speaking words[...] ) SimpleXMLElement Object ( [0] => http://lyrics.wikia.com/The_Beatles:Let_It_Be ) SimpleXMLElement Object ( [0] => 0 ) SimpleXMLElement Object ( [0] => 20851 ) I want to echo JUST the lyric part: When I find myself in times of trouble Mother Mary comes to me Speaking words of wisdom Let it be And in my hour of darkness She is standing right in front of me Speaking words[...] But I'm clueless, with everything having the Object [0], I'm not sure how to grab the particular part that I want. Can anyone help me out or point me in the right direction?
×
×
  • 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.