adding product strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
today
Forum Newbie
Posts: 7
Joined: Thu Jan 26, 2006 12:44 pm

adding product strings

Post by today »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Sorry, I am relatively new with php.  I havent been able to find out how to do this anywhere.  This is the section i am having trouble with:

Code: Select all

if ($rowcount > 0) {
		$total_cost = 0;
		$total_shipping = 0;
		echo "<h3> Order # $cart_id</h3><b> $row[0]</b>\n";
		echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"6\" bgcolor=\"#000000\">\n";
		echo "<tr bgcolor=\"#FFFFCE\" class=\"cart\"><td 

align=\"center\"><b>Code</b></td><td><b>Item</b></td><td><b>Quantity</b></td><td><b>Unit Price</b></td><td 

align=\"right\"><b>Total</b></td></tr>\n";
    	while ($row = mysql_fetch_array($rs)) {
			echo "<tr valign=\"top\" bgcolor=\"#FFFFFF\" class=\"cart\">\n";
			echo "	<td align=\"center\">$row[1]</td>\n";
			echo "	<td> $row[2] ";
			if ($row[7] <> '') {
				echo "<br><b>Custom Text:</b><i> $row[7]</i>";
			}
			if ($row[8] <> '') {
				echo "<br><b>Style:</b><i> $row[8]</i>";
			}
			echo "<br><b>Shipping: </b> $row[5] ". sprintf("\$%.2f", $row[6]) ."\n";
			echo "</td>\n";
			echo "	<td align=\"middle\">$row[3]</td>\n";
			echo "	<td align=\"right\"> ". sprintf("\$%.2f", $row[4]) ." </td>\n";
			$tc = ($row[3] * $row[4]);
			echo "	<td align=\"right\"> ". sprintf("\$%.2f", $tc) ." </td>\n";
			echo "</tr>\n";
			$total_cost += $tc;
			$total_shipping += ($row[3] * $row[6]);
			$invoice_num = $row[9];
*problem line	                $productNums = "$productNums  $row[3] -> $row[1] -> $row[2],   "; 
		}


This is the line with the problem:

Code: Select all

$productNums = "$productNums  $row[3] -> $row[1] -> $row[2],   ";
It worked for awhile, and then my submit button will completely disappear (which I dont really understand how the submit button is related to this line). What I am trying to do is make a list of the products that the person is trying to buy.

Anybody know the correct way to do this? I tried multiple ways of adding strings together, but nothing seems to work - at least not consistently. At lot of ways seem to only pass the first product and then prints the rest of the products.

Thank you.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$productNums .= '  '.$row[3].' -> '.$row[1].' -> '.$row[2].',   ';
would appear to work just fine.
today
Forum Newbie
Posts: 7
Joined: Thu Jan 26, 2006 12:44 pm

Post by today »

thanks feyd ~

when I tried what you suggested, the first product was passed (using authorizeNet):


x_product_nums : 1 -> BM-11040-C -> Benchmark


And this printed on the screen:

8007 -> Gold Medal Steamin' Demon #8007 Hot Dog Machine, 1 -> BM-11040 -> Benchmark "Street Vendor" Commercial Brand 4oz Popcorn Machine Popcorn Popper, ">



(3 products were ordered)
For some reason, it cuts off the Quanity of the 2nd product, and prints the rest to the screen. That is the same problem I have been getting with other attempts as well. ???

Thank you again for your help ~
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Run this code to understand usage of single quotes and double quotes when handling strings...

Code: Select all

<pre>
<?php
echo "<br /><br /><br /><br /><br /><br />";
$temp_array = array(1, 2, 3);
$temp_var = "HI all";
echo "<br />".'$temp_array = array(1, 2, 3)';
echo "<br />".'$temp_var = "HI all"';
echo "<br />".'echo "temp_array[0]" - '."temp_array[0]";
echo "<br />".'echo "$temp_var" - '."$temp_var";
echo "<br />".'echo \'temp_array[0]\' - '.'temp_array[0]';
echo "<br />".'echo \'$temp_var\' - '.'$temp_var';
echo "<br />".'echo \'{$temp_var}\' - '.'{$temp_var}';
echo "<br />".'echo \'{$temp_array[0]}\' - '.'{$temp_array[0]}';
?>
</pre>
Output

Code: Select all

$temp_array = array(1, 2, 3)
$temp_var = "HI all"
echo "temp_array[0]" - temp_array[0]
echo "$temp_var" - HI all
echo 'temp_array[0]' - temp_array[0]
echo '$temp_var' - $temp_var
echo '{$temp_var}' - {$temp_var}
echo '{$temp_array[0]}' - {$temp_array[0]}
today
Forum Newbie
Posts: 7
Joined: Thu Jan 26, 2006 12:44 pm

Post by today »

Ok thanks for that info - but I still don't know what I am doing wrong with that line specifically.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

post your altered code where you made changes requested by feyd. If possible, it is always better if you can give the link to the working file else copy the ouput from the browser as it is and post it within

Code: Select all

tags.
today
Forum Newbie
Posts: 7
Joined: Thu Jan 26, 2006 12:44 pm

Post by today »

Changes to code:

Code: Select all

if ($rowcount > 0) {
		$total_cost = 0;
		$total_shipping = 0;
		echo "<h3> Order # $cart_id</h3><b> $row[0]</b>\n";
		echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"6\" bgcolor=\"#000000\">\n";
		echo "<tr bgcolor=\"#FFFFCE\" class=\"cart\"><td 

align=\"center\"><b>Code</b></td><td><b>Item</b></td><td><b>Quantity</b></td><td><b>Unit Price</b></td><td 

align=\"right\"><b>Total</b></td></tr>\n";
    	while ($row = mysql_fetch_array($rs)) {
			echo "<tr valign=\"top\" bgcolor=\"#FFFFFF\" class=\"cart\">\n";
			echo "	<td align=\"center\">$row[1]</td>\n";
			echo "	<td> $row[2] ";
			if ($row[7] <> '') {
				echo "<br><b>Custom Text:</b><i> $row[7]</i>";
			}
			if ($row[8] <> '') {
				echo "<br><b>Style:</b><i> $row[8]</i>";
			}
			echo "<br><b>Shipping: </b> $row[5] ". sprintf("\$%.2f", $row[6]) ."\n";
			echo "</td>\n";
			echo "	<td align=\"middle\">$row[3]</td>\n";
			echo "	<td align=\"right\"> ". sprintf("\$%.2f", $row[4]) ." </td>\n";
			$tc = ($row[3] * $row[4]);
			echo "	<td align=\"right\"> ". sprintf("\$%.2f", $tc) ." </td>\n";
			echo "</tr>\n";
			$total_cost += $tc;
			$total_shipping += ($row[3] * $row[6]);
			$invoice_num = $row[9];
			$productNums .= '  '.$row[3].' -> '.$row[1].' -> '.$row[2].',   ';    

		}
This was printed to the screen:

SBC490BISSTB -> S/S Built-In Draft Beer Dispenser Cooler, 1 -> BM-11040 -> Benchmark "Street Vendor" Commercial Brand 4oz Popcorn Machine Popcorn Popper, ">

Dont know if you will want this, but the issue is happening on the confirm page of:

http://www.concessionobsession.com

After selecting a few products and filling out the checkout page, there is a confirm page where the user is asked to enter their cc info. Thats where the above text is showing up. I am just trying to pass all the product info as hidden. I am trying to have it in the order of Quantity -> Product Number -> Name of product, .

Is that enough info?
today
Forum Newbie
Posts: 7
Joined: Thu Jan 26, 2006 12:44 pm

Post by today »

okay yeah i dont know now i just tried it and it worked. um. yeah dont know what to say. i will test it a few more times. that was weird.
today
Forum Newbie
Posts: 7
Joined: Thu Jan 26, 2006 12:44 pm

Post by today »

okay I think maybe there is only a problem when i select a product that has quotes of some kind in the name. Would that be possible? anyway I am going to try a few more times and then remove the quotes from the products and see if thats the problem.

thank you~
today
Forum Newbie
Posts: 7
Joined: Thu Jan 26, 2006 12:44 pm

Post by today »

well apparently that was the problem. i swear i checked that before too! - i must have done something wrong when i tested last time. we will see if i have any more problems with it i guess ~

Thank you for your time and help.
Post Reply