Jump to content

Array Problem


murfitUK

Recommended Posts

I've got an array called $basket which looks something like this:[0] [item_id]=>176 [quantity] =>2[1] [item_id]=>32 [quantity] =>1[2] [item_id]=>44 [quantity] =>1I then create a query to pull out all the fields from a table where the item_id is contained in $basket. SELECT * FROM ITEMS WHERE item_id IN (176,32,44). I've got this working OK.These fields include the description of the item and the cost. I'd like to be able to add these two fields to the $basket array so it looks something like this:[0] [item_id]=>176 [quantity]=>2 [desc]=>'This line will contain a description of the product etc...' [cost]=>12.34....... and so onI need to do this so I can print out a "Your Basket" page. I can only get so far using the results of the query because I need to know the quantity for each item to work out the total cost. Does anyone know how to add these fields to the $basket array? The common value in both arrays will be the item_id.

Link to comment
Share on other sites

I think you might be looking for array_push() I'm fairly new to php, but I've used a function similar to this in perl.Here's an example from the php manual:<?php$stack = array("orange", "banana");array_push($stack, "apple", "raspberry");print_r($stack);?> The above example will output:Array( [0] => orange [1] => banana [2] => apple [3] => raspberry) So, the array $stack started with two items in it, then two more items were added to the end of the array. I think that's what you were trying to do. Hope this helps!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...