Avatar of Johnny
JohnnyFlag for United States of America

asked on 

build item array for authorize.net for products

we are continuing from question
https://www.experts-exchange.com/questions/27180572/how-to-use-multiple-tables-to-join-information-to-send-to-authorize-net.html

// item-qty-color-size-price
$line_items = array(
        "item1<|>2<|>Black<|>4 inches long<|>18.95",
        "item2<|>3<|>Purple<|>16 inches long<|>39.99",
        .......
        "item5<|>3<|>White<|>4 inches long<|>21.99");
       
using the information from the last posted question please.
PHP

Avatar of undefined
Last Comment
Johnny
Avatar of EMB01
EMB01
Flag of United States of America image

Reposting for easier access:

$transaction->setFields(
                array(
                'invoice_num' => $invoice_number,
                'amount' => $amount,
                'description' => $description,
                'customer_ip' => $cust_ip,
                'cust_id' => $mysql_last_id,
                'phone' => $telephone,
                'card_num' => $credit_card,
                'exp_date' => $expiration_date,
                'first_name' => $cardholder_first_name,
                'last_name' => $cardholder_last_name,
                'address' => $billing_address,
                'city' => $billing_city,
                'state' => $billing_state,
                'zip' => $billing_zip,
                'email' => $email,
                'card_code' => $cvv,
                'ship_to_first_name' => $recipient_first_name,
                'ship_to_last_name' => $recipient_last_name,
                'ship_to_address' => $shipping_address,
                'ship_to_city' => $shipping_city,
                'ship_to_state' => $shipping_state,
                'ship_to_zip' => $shipping_zip,
                'header_email_receipt' => 'This E-Mail is confermation of your recent order with xxxx.com',
                'footer_email_receipt' => 'Should you need to contact us for any reason, Please E-Mail support@xxxx.com or call (800) XXX-XXXX',
                
                )

Open in new window


--
-- Table structure for table `item_sales`
--

CREATE TABLE IF NOT EXISTS `item_sales` (
  `id` int(10) NOT NULL auto_increment,
  `invoice_number` varchar(150) character set latin1 collate latin1_general_ci NOT NULL,
  `qty_item_1` varchar(3) character set latin1 collate latin1_general_ci NOT NULL,
  `color_item_1` varchar(25) character set latin1 collate latin1_general_ci NOT NULL,
  `size_item_1` varchar(3) character set latin1 collate latin1_general_ci NOT NULL,
  `qty_item_2` varchar(3) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `color_item_2` varchar(25) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `size_item_2` varchar(2) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `qty_item_3` varchar(3) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `color_item_3` varchar(25) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `size_item_3` varchar(2) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `qty_item_4` varchar(3) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `color_item_4` varchar(25) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `size_item_4` varchar(2) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `qty_item_5` varchar(3) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `color_item_5` varchar(25) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `size_item_5` varchar(2) character set latin1 collate latin1_general_ci NOT NULL default '0',
  `comment` text character set latin1 collate latin1_general_ci NOT NULL,
  `status` enum('needs review','new','pending','assembling','shipped') character set latin1 collate latin1_general_ci NOT NULL default 'new',
  `date_created` datetime NOT NULL,
  `date_last_updated` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `note` text character set latin1 collate latin1_general_ci NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

--
-- Dumping data for table `item_sales`
--

INSERT INTO `item_sales` (`id`, `invoice_number`, `qty_item_1`, `color_item_1`, `size_item_1`, `qty_item_2`, `color_item_2`, `size_item_2`, `qty_item_3`, `color_item_3`, `size_item_3`, `qty_item_4`, `color_item_4`, `size_item_4`, `qty_item_5`, `color_item_5`, `size_item_5`, `comment`, `status`, `date_created`, `date_last_updated`, `note`) VALUES
(2, 'B80-14P-S9B-VXE', '1', 'Black', '4', '0', 'NULL', 'NU', '0', 'NULL', 'NU', '0', 'NULL', 'NU', '0', 'NULL', 'NU', 'test', 'new', '2011-07-05 12:51:56', '2011-07-05 12:52:08', ''),
(3, 'IF6-CTK-ZNJ-NWR', '5', 'White', '4', '0', 'NULL', 'NU', '0', 'NULL', 'NU', '0', 'NULL', 'NU', '0', 'NULL', 'NU', 'test', 'new', '2011-07-05 12:52:55', '2011-07-05 12:53:14', ''),
(4, '060-K7V-H2W-4EQ', '10', 'Orange', '4', '0', 'NULL', 'NU', '0', 'NULL', 'NU', '0', 'NULL', 'NU', '0', 'NULL', 'NU', 'test', 'new', '2011-07-05 12:54:18', '2011-07-05 12:54:32', '');

Open in new window


--
-- Table structure for table `item_size`
--

CREATE TABLE IF NOT EXISTS `item_size` (
  `id` int(10) NOT NULL auto_increment,
  `size` int(2) NOT NULL,
  `price` decimal(4,2) NOT NULL,
  `active` enum('0','1') NOT NULL default '1',
  `note` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

--
-- Dumping data for table `item_size`
--

INSERT INTO `item_size` (`id`, `size`, `price`, `active`, `note`) VALUES
(1, 4, 1.99, '1', ''),
(2, 6, 2.49, '1', ''),
(3, 10, 2.79, '1', ''),
(4, 12, 2.99, '1', ''),
(5, 16, 3.49, '0', '');

Open in new window


function get_price($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);

                for ($i = 1; $i < 6; $i++) {
                
                        // get query to find price based on size
                        $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                        echo $query."<br>";
                        $result = mysql_query($query);

                        if ($result) {

                                        // get price
                                        while ($row = mysql_fetch_assoc($result)) {
                                                        $price[] = $row['price'];
                                        }

                        } else {
                        
                                $price[] = NULL;
                        
                        }
                        
                }
    
                return $price;
        
}
$invoice_number="E5S-6KZ-BV0-FV9";
$amount=get_price($invoice_number);
var_dump($amount);
?>

Open in new window


It's probably easiest to do this with another function.  The best case scenario would be to use class instances.

function get_desc($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);

                        // get query to find price based on size
                        $query = "SELECT `description` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                        echo $query."<br>";
                        $result = mysql_query($query);

                        if ($result) {

                                        // get desc
                                        while ($row = mysql_fetch_assoc($result)) {
                                                        $desc = $row['description'];
                                        }

                        } else {
                        
                                $desc = NULL;
                        
                        }

    
                return $desc;
        
}
$invoice_number="E5S-6KZ-BV0-FV9";
$desc=get_desc($invoice_number);
var_dump($desc);
?>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

I looked at the other question and I think EMB01 is helping you with the question as far as it goes, but EMB01 alluded to concerns about the design of the data base tables, and I think I would echo that concern.  You might want to get a DBA to help you design the tables and queries.  Shopping cart programming is a very well-understood design pattern (for more than 12 years now) and you can benefit a lot from using the standard designs.

In the instant case, it looks like your query would look something like this:

SELECT item, qty, color, size, price FROM myTable ORDER BY item

And the PHP code that processed the query results set would look something like this:

$line_items = array();
while ($row = mysql_fetch_array($result))
{
    $line_items[] = implode('<|>', $row);
}

The implode() function is used to insert the column separators into each element of the array.
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

thanks EMB01 for continuing this question.
as we are trying to build this below
// item-qty-color-size-price
$line_items = array(
        "item1<|>2<|>Black<|>4 inches long<|>18.95",
        "item2<|>3<|>Purple<|>16 inches long<|>39.99",
        .......
        "item5<|>3<|>White<|>4 inches long<|>21.99");

would we not have to use you nifty code from the last question, to get the price, and sadly there is no description field inthe database, justw what you see from the mysql tables, but nothing changes only size and color, and quanity


--------------------------------------------------------------------
Ray_Paseur, thanks for the input (always welcome)
we went from one product bundle to multiple, so i had to roll with it.
but this setup is to control whats needed a normal item shopping cart like osccomerse style was not needed, they wanted to control aspects of the admin back end, and sell the items, basically they have a product that changes colors(for available materials) and size for now its set sizes that will change in the future and is unknown right now the custom sizes.) so i came up with ok track the sizes in a table the colors in table(that can be changed in the database esaly. so this is what i came up with.
Avatar of EMB01
EMB01
Flag of United States of America image

I can make you a function to do that, too, if you want.  P.S.  Mind your own business ray!  LOL, point theif!
Avatar of EMB01
EMB01
Flag of United States of America image

@Pern:  I need to know how to get the title or name, such as "item1."  I see color, size and price are in the database, but where is the title?  Thanks.
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

just asking off the top of my head here, something like this, mind you its not code just idea.


end result to look something like this when properly done
// item-qty-color-size-price
$line_items = array(
        "item1<|>2<|>Black<|>4 inches long<|>18.95",
        "item2<|>3<|>Purple<|>16 inches long<|>39.99",
        .......
        "item5<|>3<|>White<|>4 inches long<|>21.99");

$amount=get_price($invoice_number);

$query = "SELECT * FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
$result = mysql_query($query);

if ($result) {

		// set up string
		while ($row = mysql_fetch_assoc($result)) {
		// will need proper format and loop for 0-4(1 to 5 items loop, if not == 0)
		$row['qty_item_X'] <|> $row['color_item_X'] <|> $row['size_item_X'] <|> $amount[(X-1)];
		}

} else {

	echo"mysql query failed" die(mysql error setup here);

}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

inches long would be the product description, and again would not change so it be

qty 5: Black 4 inches long : $1.99

something along those lines
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

ive added 0 to the database if a product was not used for the 5 items ordered.
Avatar of EMB01
EMB01
Flag of United States of America image

Try this, please.
function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
		
			for ($i = 1; $i < 6; $i++) {

						// get other info
						$query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
						echo $query;
						$result = mysql_query($query);

                        if ($result) {

                                        $string[] = $invoice_number;
										while ($row = mysql_fetch_array($result))
										{
											$string[] = $row['qty_item_$i'];
											$string[] = $row['color_item_$i'];
											$string[] = $row['size_item_$i'];
										}

                        } else {
                        
                                $string = NULL;
                        
                        }
		
                        // get query to find price based on size
                        $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                        echo $query;
						$result = mysql_query($query);

                        if ($result) {

                                        $string[] = $invoice_number;
										while ($row = mysql_fetch_array($result))
										{
											$string[] = $row['price'];
										}

                        } else {
                        
                                $string[] = NULL;
                        
                        }
						
						 $line_items[] = implode("<|>", $string);
 
        }
		
	return $line_items;
	
}
$invoice_number="E5S-6KZ-BV0-FV9";
$li=get_line_items($invoice_number);
var_dump($li);

Open in new window

Avatar of EMB01
EMB01
Flag of United States of America image

Sorry, had to change something.  Try this:
function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
		
			for ($i = 1; $i < 6; $i++) {

				// get other info
				$query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
				echo $query;
				$result = mysql_query($query);
						
                if ($result) {

                    $string[] = $invoice_number;
					while ($row = mysql_fetch_assoc($result)) {
					
						$string[] = $row['qty_item_$i'];
						$string[] = $row['color_item_$i'];
						$string[] = $row['size_item_$i'];
						
					}

                } else {
                        
                    $string = NULL;
                        
                }
		
                // get query to find price based on size
                $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                echo $query;
				$result = mysql_query($query);

                if ($result) {

                    $string[] = $invoice_number;
					while ($row = mysql_fetch_assoc($result)) {
						
						$string[] = $row['price'];
					}

                } else {
                        
                    $string[] = NULL;
                        
                }
						
				$line_items[] = implode("<|>", $string);
 
        }
		
	return $line_items;
	
}
$invoice_number="E5S-6KZ-BV0-FV9";
$li=get_line_items($invoice_number);
var_dump($li);
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

returned
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')array(5) { [0]=> string(15) "E5S-6KZ-BV0-FV9" [1]=> string(15) "E5S-6KZ-BV0-FV9" [2]=> string(15) "E5S-6KZ-BV0-FV9" [3]=> string(15) "E5S-6KZ-BV0-FV9" [4]=> string(15) "E5S-6KZ-BV0-FV9" }

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

revised it to see it better

function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
                
                        for ($i = 1; $i < 6; $i++) {

                                // get other info
                                $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                                echo $query;
                                $result = mysql_query($query);
                                                
                if ($result) {

                    $string[] = $invoice_number;
                                        while ($row = mysql_fetch_assoc($result)) {
                                        
                                                $string[] = $row['qty_item_$i'];
                                                $string[] = $row['color_item_$i'];
                                                $string[] = $row['size_item_$i'];
                                                
                                        }

                } else {
                        
                    $string = NULL;
                        
                }
                
                // get query to find price based on size
                $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                echo $query."<br>";
                                $result = mysql_query($query);

                if ($result) {

                    $string[] = $invoice_number;
                                        while ($row = mysql_fetch_assoc($result)) {
                                                
                                                $string[] = $row['price'];
                                        }

                } else {
                        
                    $string[] = NULL;
                        
                }
                                                
                                $line_items[] = implode("<|>", $string);
 
        }
                
        return $line_items;
        
}
$invoice_number="E5S-6KZ-BV0-FV9";
$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')
array(5) {
  [0]=>
  string(15) "E5S-6KZ-BV0-FV9"
  [1]=>
  string(15) "E5S-6KZ-BV0-FV9"
  [2]=>
  string(15) "E5S-6KZ-BV0-FV9"
  [3]=>
  string(15) "E5S-6KZ-BV0-FV9"
  [4]=>
  string(15) "E5S-6KZ-BV0-FV9"
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

grr forgot im testing other things and have multible invoice numbers i clear them out form time to time too

heres the working invoice number
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
array(5) {
  [0]=>
  string(22) "V1C-LU1-E7N-1EO<|>1.99"
  [1]=>
  string(22) "V1C-LU1-E7N-1EO<|>2.49"
  [2]=>
  string(22) "V1C-LU1-E7N-1EO<|>2.79"
  [3]=>
  string(22) "V1C-LU1-E7N-1EO<|>2.99"
  [4]=>
  string(22) "V1C-LU1-E7N-1EO<|>3.49"
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

when we are all done, im not understanding why you have
$string[] = $invoice_number;
Avatar of EMB01
EMB01
Flag of United States of America image

Try this and tell me what it says, please:
function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
                
                        for ($i = 1; $i < 6; $i++) {

                                // get other info
                                $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                                echo $query;
                                $result = mysql_query($query);
                                                
                if ($result) {

                    $string[] = $invoice_number;
                                        while ($row = mysql_fetch_assoc($result)) {
                                        
                                                $string[] = $row['qty_item_$i'];
                                                $string[] = $row['color_item_$i'];
                                                $string[] = $row['size_item_$i'];
                                                
                                        }

                } else {
                        
                    $string = NULL;
                        
                }
                
                // get query to find price based on size
                $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                echo $query."<br>";
                                $result = mysql_query($query);

                if ($result) {

                                        while ($row = mysql_fetch_assoc($result)) {
                                                
                                                $string[] = $row['price'];
                                        }

                } else {
                        
                    $string[] = NULL;
                        
                }
                                                
                                $line_items[] = implode("<|>", $string);
 
        }
                
        return $line_items;
        
}
$invoice_number="E5S-6KZ-BV0-FV9";
$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of EMB01
EMB01
Flag of United States of America image

If that doesn't work, try this:
function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
                
                        for ($i = 1; $i < 6; $i++) {

                                // get other info
                                $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                                echo $query;
                                $result = mysql_query($query);
                                                
                if ($result) {

                    $string[] = $invoice_number;
                                        while ($row = mysql_fetch_assoc($result)) {
                                        
                                                $string[] = $row['qty_item_'.$i];
                                                $string[] = $row['color_item_'.$i];
                                                $string[] = $row['size_item_'.$i];
                                                
                                        }

                } else {
                        
                    $string = NULL;
                        
                }
                
                // get query to find price based on size
                $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
                echo $query."<br>";
                                $result = mysql_query($query);

                if ($result) {

                                        while ($row = mysql_fetch_assoc($result)) {
                                                
                                                $string[] = $row['price'];
                                        }

                } else {
                        
                    $string[] = NULL;
                        
                }
                                                
                                $line_items[] = implode("<|>", $string);
 
        }
                
        return $line_items;
        
}
$invoice_number="E5S-6KZ-BV0-FV9";
$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

returned both basically the same
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')

Warning: implode() [function.implode]: Invalid arguments passed in /home/roll/public_html/payment-form/lineitems.php on line 61
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')

Warning: implode() [function.implode]: Invalid arguments passed in /home/roll/public_html/payment-form/lineitems.php on line 61
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')

Warning: implode() [function.implode]: Invalid arguments passed in /home/roll/public_html/payment-form/lineitems.php on line 61
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')

Warning: implode() [function.implode]: Invalid arguments passed in /home/roll/public_html/payment-form/lineitems.php on line 61
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'E5S-6KZ-BV0-FV9')

Warning: implode() [function.implode]: Invalid arguments passed in /home/roll/public_html/payment-form/lineitems.php on line 61
array(5) {
  [0]=>
  NULL
  [1]=>
  NULL
  [2]=>
  NULL
  [3]=>
  NULL
  [4]=>
  NULL
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

hang on my bad yet again invoice number i got check that
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
array(5) {
  [0]=>
  string(4) "1.99"
  [1]=>
  string(4) "2.49"
  [2]=>
  string(4) "2.79"
  [3]=>
  string(4) "2.99"
  [4]=>
  string(4) "3.49"
}

Open in new window

Avatar of EMB01
EMB01
Flag of United States of America image

If that's not working, lets take a step back.  Try this and tell me what it does:
function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
                
        for ($i = 1; $i < 6; $i++) {

            // get other info
            $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
            echo $query;
            $result = mysql_query($query);
                                                
            if ($result) {

				$string[] = $invoice_number;
				while ($row = mysql_fetch_assoc($result)) {
											
					$string[] = $row['qty_item_'.$i];
					$string[] = $row['color_item_'.$i];
					$string[] = $row['size_item_'.$i];
													
				}

            } else {
                        
                $string[] = NULL;
                        
            }
                
        }
                
        return $string;
        
}
$invoice_number="E5S-6KZ-BV0-FV9";
$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

returned


** added <br> for easy of looking better return
function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
                
        for ($i = 1; $i < 6; $i++) {

            // get other info
            $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
            echo $query."<br>";
            $result = mysql_query($query);
                                                
            if ($result) {

                                $string[] = $invoice_number;
                                while ($row = mysql_fetch_assoc($result)) {
                                                                                        
                                        $string[] = $row['qty_item_'.$i];
                                        $string[] = $row['color_item_'.$i];
                                        $string[] = $row['size_item_'.$i];
                                                                                                        
                                }

            } else {
                        
                $string[] = NULL;
                        
            }
                
        }
                
        return $string;
        
}

$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
array(5) {
  [0]=>
  NULL
  [1]=>
  NULL
  [2]=>
  NULL
  [3]=>
  NULL
  [4]=>
  NULL
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

oh i placed invoice number at the top too



mysql_select_db($db_Database, $mysql_link)
or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect');
$invoice_number="V1C-LU1-E7N-1EO";

function get_line_items($invoice_number) {
Avatar of EMB01
EMB01
Flag of United States of America image

We're getting there:
mysql_select_db($db_Database, $mysql_link)
or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect');
$invoice_number="V1C-LU1-E7N-1EO";

function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
                
        for ($i = 1; $i < 6; $i++) {

            // get other info
            $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
            echo $query."<br>";
            $result = mysql_query($query);
                                                
            if ($result) {

                                $string[] = $invoice_number;
                                while ($row = mysql_fetch_assoc($result)) {
                                                                                        
                                        $string[] = $row["qty_item_$i"];
                                        $string[] = $row["color_item_$i"];
                                        $string[] = $row["size_item_$i"];
                                                                                                        
                                }

            } else {
                        
                $string[] = "result is false";
                        
            }
                
        }
                
        return $string;
        
}

$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
array(5) {
  [0]=>
  string(15) "result is false"
  [1]=>
  string(15) "result is false"
  [2]=>
  string(15) "result is false"
  [3]=>
  string(15) "result is false"
  [4]=>
  string(15) "result is false"
}
Avatar of EMB01
EMB01
Flag of United States of America image

I think I found the problem.  Try this:
mysql_select_db($db_Database, $mysql_link)
or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect');
$invoice_number="V1C-LU1-E7N-1EO";

function get_line_items($invoice_number) {

        // get product id
        $invoice_number = mysql_real_escape_string($invoice_number);
                
        for ($i = 1; $i < 6; $i++) {

            // get other info
            $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number";
            echo $query."<br>";
            $result = mysql_query($query);
                                                
            if ($result) {

                                $string[] = $invoice_number;
                                while ($row = mysql_fetch_assoc($result)) {
                                                                                        
                                        $string[] = $row["qty_item_$i"];
                                        $string[] = $row["color_item_$i"];
                                        $string[] = $row["size_item_$i"];
                                                                                                        
                                }

            } else {
                        
                $string[] = "result is false";
                        
            }
                
        }
                
        return $string;
        
}

$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

Parse error: syntax error, unexpected '"' in /home/roll/public_html/payment-form/lineitems.php on line 23

that line is

            $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number";
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

changed to add '"
$query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number"'";


now says
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/roll/public_html/payment-form/lineitems.php on line 23
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

got it need a . for value
$query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."'";

now returns

SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
array(20) {
  [0]=>
  string(15) "V1C-LU1-E7N-1EO"
  [1]=>
  string(1) "1"
  [2]=>
  string(5) "Black"
  [3]=>
  string(1) "4"
  [4]=>
  string(15) "V1C-LU1-E7N-1EO"
  [5]=>
  string(1) "2"
  [6]=>
  string(5) "Black"
  [7]=>
  string(1) "6"
  [8]=>
  string(15) "V1C-LU1-E7N-1EO"
  [9]=>
  string(1) "3"
  [10]=>
  string(5) "Black"
  [11]=>
  string(2) "10"
  [12]=>
  string(15) "V1C-LU1-E7N-1EO"
  [13]=>
  string(1) "4"
  [14]=>
  string(5) "White"
  [15]=>
  string(2) "12"
  [16]=>
  string(15) "V1C-LU1-E7N-1EO"
  [17]=>
  string(1) "5"
  [18]=>
  string(5) "White"
  [19]=>
  string(2) "16"
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

need price and to build and i think we have it
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

wow i wouldn't have come up with this in a million years...
Avatar of EMB01
EMB01
Flag of United States of America image

Cool, good catch on the apostrophe.  Try:
mysql_select_db($db_Database, $mysql_link)
or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect');
$invoice_number="V1C-LU1-E7N-1EO";

function get_line_items($invoice_number) {

    // get product id
    $invoice_number = mysql_real_escape_string($invoice_number);
                
    for ($i = 1; $i < 6; $i++) {

        // get other info
        $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."'";
        echo $query."<br>";
        $result = mysql_query($query);
        
        if ($result) {

            $string[] = $invoice_number;
            while ($row = mysql_fetch_assoc($result)) {
    
                $string[] = $row["qty_item_$i"];
                $string[] = $row["color_item_$i"];
                $string[] = $row["size_item_$i"];
				
            }

        } else {
                        
            $string[] = NULL;
                        
        }
                
        // get query to find price based on size
        $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
        echo $query."<br>";
        $result = mysql_query($query);

        if ($result) {

            while ($row = mysql_fetch_assoc($result)) {
             
                $string[] = $row['price'];
            }

        } else {
                        
            $string[] = NULL;
                        
        }
           
        $line_items[] = implode("<|>", $string);
 
    }
                
    return $line_items;
        
}

$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

looks like its adding to the string is that right or are we breaking it down to 1,2...5?
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
array(5) {
  [0]=>
  string(38) "V1C-LU1-E7N-1EO<|>1<|>Black<|>4<|>1.99"
  [1]=>
  string(79) "V1C-LU1-E7N-1EO<|>1<|>Black<|>4<|>1.99<|>V1C-LU1-E7N-1EO<|>2<|>Black<|>6<|>2.49"
  [2]=>
  string(121) "V1C-LU1-E7N-1EO<|>1<|>Black<|>4<|>1.99<|>V1C-LU1-E7N-1EO<|>2<|>Black<|>6<|>2.49<|>V1C-LU1-E7N-1EO<|>3<|>Black<|>10<|>2.79"
  [3]=>
  string(163) "V1C-LU1-E7N-1EO<|>1<|>Black<|>4<|>1.99<|>V1C-LU1-E7N-1EO<|>2<|>Black<|>6<|>2.49<|>V1C-LU1-E7N-1EO<|>3<|>Black<|>10<|>2.79<|>V1C-LU1-E7N-1EO<|>4<|>White<|>12<|>2.99"
  [4]=>
  string(205) "V1C-LU1-E7N-1EO<|>1<|>Black<|>4<|>1.99<|>V1C-LU1-E7N-1EO<|>2<|>Black<|>6<|>2.49<|>V1C-LU1-E7N-1EO<|>3<|>Black<|>10<|>2.79<|>V1C-LU1-E7N-1EO<|>4<|>White<|>12<|>2.99<|>V1C-LU1-E7N-1EO<|>5<|>White<|>16<|>3.49"
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

V1C-LU1-E7N-1EO we are using the invoice number here is this not supposed to be item 1, item 2,.... item 5??
in our list
/ item-qty-color-size-price
$line_items = array(
        "item1<|>2<|>Black<|>4 inches long<|>18.95",
        "item2<|>3<|>Purple<|>16 inches long<|>39.99",
        .......
        "item5<|>3<|>White<|>4 inches long<|>21.99");
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

i just thought of another thing are we not going to need
/ item-qty-color-size-price(item)-price(total)
$line_items = array(
        "item1<|>2<|>Black<|>4 inches long<|>18.95<|>{qty*item_price}",
        "item2<|>3<|>Purple<|>16 inches long<|>39.99<|>{qty*item_price}",
        .......
        "item5<|>3<|>White<|>4 inches long<|>21.99<|>{qty*item_price}");
Avatar of EMB01
EMB01
Flag of United States of America image

No, let's clear that like this:
mysql_select_db($db_Database, $mysql_link)
or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect');
$invoice_number="V1C-LU1-E7N-1EO";

function get_line_items($invoice_number) {

    // get product id
    $invoice_number = mysql_real_escape_string($invoice_number);
                
    for ($i = 1; $i < 6; $i++) {

		// clear array
		$string = array();
        // get other info
        $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."'";
        echo $query."<br>";
        $result = mysql_query($query);
        
        if ($result) {

            $string[] = $invoice_number;
            while ($row = mysql_fetch_assoc($result)) {
    
                $string[] = $row["qty_item_$i"];
                $string[] = $row["color_item_$i"];
                $string[] = $row["size_item_$i"];
				
            }

        } else {
                        
            $string[] = NULL;
                        
        }
                
        // get query to find price based on size
        $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
        echo $query."<br>";
        $result = mysql_query($query);

        if ($result) {

            while ($row = mysql_fetch_assoc($result)) {
             
                $string[] = $row['price'];
            }

        } else {
                        
            $string[] = NULL;
                        
        }
           
        $line_items[] = implode("<|>", $string);
 
    }
                
    return $line_items;
        
}

$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

looking  a lot better now
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'V1C-LU1-E7N-1EO')
array(5) {
  [0]=>
  string(38) "V1C-LU1-E7N-1EO<|>4<|>Black<|>4<|>1.99"
  [1]=>
  string(38) "V1C-LU1-E7N-1EO<|>2<|>Black<|>6<|>2.49"
  [2]=>
  string(39) "V1C-LU1-E7N-1EO<|>3<|>Black<|>10<|>2.79"
  [3]=>
  string(39) "V1C-LU1-E7N-1EO<|>7<|>White<|>12<|>2.99"
  [4]=>
  string(40) "V1C-LU1-E7N-1EO<|>12<|>White<|>16<|>3.49"
}

Open in new window

Avatar of EMB01
EMB01
Flag of United States of America image

You asked about the existence of $string[] = $invoice_number; in the function.  I put that there because I don't see any other title or name to put there.
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

just to note heres what it look like if only one product it selected
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
array(5) {
  [0]=>
  string(38) "L87-8RE-0Q2-KSR<|>1<|>Black<|>4<|>1.99"
  [1]=>
  string(30) "L87-8RE-0Q2-KSR<|>0<|>NULL<|>0"
  [2]=>
  string(30) "L87-8RE-0Q2-KSR<|>0<|>NULL<|>0"
  [3]=>
  string(30) "L87-8RE-0Q2-KSR<|>0<|>NULL<|>0"
  [4]=>
  string(30) "L87-8RE-0Q2-KSR<|>0<|>NULL<|>0"
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

using or example it be

invoice number: V1C-LU1-E7N-1EO

item 1: qty 4: Black 4 inches long : $1.99
item 2: qty 2: Black 6 inches long : $2.49
item 3: qty 3: Black 10 inches long : $2.79
item 4: qty 7: Black 12 inches long : $2.99
item 5: qty 12: Black 16 inches long : $3.49


i have a product name but its unique ill add it in later, but if we make the item list like that ill be ok

ps: i still need ot add s&*h and tax to ohio, might make that a different question later tonight as i have to go 100+ miles one way here in a bit for my other park of my job, road trip
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

let me understand this here

with auth.net
$line_items = array(

how does this allow us to send the item info for multiple items do we just send price for each item and it extended the price totals?

do we need item 1,item2, ...item 5 as item 1: etc or is this the name of the product.

never sent info here sent know how the items works for auth.net
Avatar of EMB01
EMB01
Flag of United States of America image

...  This page is getting slower!  I hate that.

Anyway, we can add an additional quantifier to check before adding to the array.  
mysql_select_db($db_Database, $mysql_link)
or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect');
$invoice_number="V1C-LU1-E7N-1EO";

function get_line_items($invoice_number) {

    // get product id
    $invoice_number = mysql_real_escape_string($invoice_number);
                
    for ($i = 1; $i < 6; $i++) {

		// clear array
		$string = array();
        // get other info
        $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."'";
        echo $query."<br>";
        $result = mysql_query($query);
        
        if ($result) {
		
			$row = mysql_fetch_assoc($result);
			
			if ($row["qty_item_$i"] > 0) {
		
				$string[] = $invoice_number;
				while ($row) {
		
					$string[] = $row["qty_item_$i"];
					$string[] = $row["color_item_$i"];
					$string[] = $row["size_item_$i"];
					
				}
				
			}

        } else {
                        
            $string[] = NULL;
                        
        }
                
        // get query to find price based on size
        $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
        echo $query."<br>";
        $result = mysql_query($query);

        if ($result) {

            while ($row = mysql_fetch_assoc($result)) {
             
                $string[] = $row['price'];
            }

        } else {
                        
            $string[] = NULL;
                        
        }
           
        $line_items[] = implode("<|>", $string);
 
    }
                
    return $line_items;
        
}

$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

if i get this right the descrition then should be

12 inches long *product name* ie

"12 inches long big box"

qty,color,description, each price

4,Black, 12 inches long big box,1.99
etc
Avatar of EMB01
EMB01
Flag of United States of America image

Also, you can remove the NULLs:
mysql_select_db($db_Database, $mysql_link)
or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect');
$invoice_number="V1C-LU1-E7N-1EO";

function get_line_items($invoice_number) {

    // get product id
    $invoice_number = mysql_real_escape_string($invoice_number);
                
    for ($i = 1; $i < 6; $i++) {

		// clear array
		$string = array();
        // get other info
        $query = "SELECT `qty_item_$i`, `color_item_$i`, `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."'";
        echo $query."<br>";
        $result = mysql_query($query);
        
        if ($result) {
		
			$row = mysql_fetch_assoc($result);
			
			if ($row["qty_item_$i"] > 0) {
		
				$string[] = $invoice_number;
				while ($row) {
		
					$string[] = $row["qty_item_$i"];
					$string[] = $row["color_item_$i"];
					$string[] = $row["size_item_$i"];
					
				}
				
			}

        }
                
        // get query to find price based on size
        $query = "SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_$i` FROM `item_sales` WHERE `invoice_number` = '".$invoice_number."')";
        echo $query."<br>";
        $result = mysql_query($query);

        if ($result) {

            while ($row = mysql_fetch_assoc($result)) {
             
                $string[] = $row['price'];
            }

        }
           
        $line_items[] = implode("<|>", $string);
 
    }
                
    return $line_items;
        
}

$li=get_line_items($invoice_number);
echo "<pre>";
var_dump($li);
echo "</pre>";
?>

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

what the !!!

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /home/roll/public_html/payment-form/lineitems.php on line 39

that line reads
                                        $string[] = $row["color_item_$i"];
Avatar of EMB01
EMB01
Flag of United States of America image

Okay, forget that for a sec.  let's try to get this desc like you want it.

>>  12 inches long *product name* ie

I need to know where you're getting the product name from.  It's not in the database as there's no field for it.
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

couldn't we just make it make an array?

heres why

i need to be able to check the qty so i can add shipping costs, i also need to check qty and item price for extended total

so cant we name fields in an array like this

[0]

[qty]>4
[color]>black
[size]>12

then i call it something like [0][color] to get black right?

sorry i dont know arrays much
but this would allow me to look at the s&h based on qty and also add up totals
then build this for the auth.net
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

as i said the product is one product various colors and sizes, im not wanting to give out the name of the product as its unique and dont want others looking at this post to goto the website, not just yet at least

if you give me a way to tell you the site url id be happy to pass that to you by yourself and youll understand name it "BIG BOX" for now please
ASKER CERTIFIED SOLUTION
Avatar of EMB01
EMB01
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

yes thats supper close

is there a way for me to get the return of the qty and price by them selves?
from this array we did please

ill close this (accept it) and move on here, ill ask if i have any other problems along th way, ill post the question url at the bottom if i do
SELECT `qty_item_1`, `color_item_1`, `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_1` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_2`, `color_item_2`, `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_2` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_3`, `color_item_3`, `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_3` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_4`, `color_item_4`, `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_4` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
SELECT `qty_item_5`, `color_item_5`, `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR'
SELECT `price` FROM `item_size` WHERE `size` = (SELECT `size_item_5` FROM `item_sales` WHERE `invoice_number` = 'L87-8RE-0Q2-KSR')
array(5) {
  [0]=>
  string(41) "Item 1<|>1<|>Black<|>4 inches long<|>1.99"
  [1]=>
  string(33) "Item 2<|>0<|>NULL<|>0 inches long"
  [2]=>
  string(33) "Item 3<|>0<|>NULL<|>0 inches long"
  [3]=>
  string(33) "Item 4<|>0<|>NULL<|>0 inches long"
  [4]=>
  string(33) "Item 5<|>0<|>NULL<|>0 inches long"
}

Open in new window

Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

plus ill play with the sandbox later to see how that all works for multiple passed items with auth.net
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

thank you so very much for the solution
Avatar of EMB01
EMB01
Flag of United States of America image

The purpose of this function is to create an array of strings suited for auth.net.  If you want to simply return a qty or price or desc, we should build a separate function.

You're welcome, btw. :)
Avatar of Johnny
Johnny
Flag of United States of America image

ASKER

ok then ill ask that later in a new question i have to go for about 6 hours
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo