Re: variables / reading files

From: Date: Sun, 24 Jun 2001 01:02:47 +0000
Subject: Re: variables / reading files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55006@lists.php.net to get a copy of this message
OK, thanks for that Chris. I did get it in the end, with something very similar to what you suggested: $message = ""; while ( .... ) { $var1 = $row["1"]; ... etc $item = "$var1 $var2 $var3 etc"; $message = $message . $item . "\n"; } Your solution is cleaner so I'll change it over. I'd written the whole cart in one sitting up to then, and was fairly cross-eyed by that stage. On Sat, 23 Jun 2001, Christopher Ostmo wrote: > Michael Hall pressed the little lettered thingies in this order... > > > > > I'm stuck on a piece of code for a shopping cart. > > > > I'm on the final page where the buyer clicks BUY and several things > > happen. I want to loop through the table that stores the session info and > > extract details such as item, price, quantity, subtotal and assign all this > > info to one variable: > > > > $var = the output of a while($row = mysql_fetch_array($query)) statement > > A > > Why I'm trying to do this is I'd like to store all the purchase details in > > one variable for inclusion in an email: > > > > $message = $var; // (from above) > > mail($address,$subject,$message); > > > > I'd also like to put the info in that same variable into a table that > > records actual sales data: > > > > $details = $var; > > insert into table ('details') values ('$details'); > > > > I know there must be a (probably very easy) way, but just can't crack it. > > > > $result = mysql("DBName","QUERY"); > while ($row = mysql_fetch_row($result)) { > $var = $row[0]; > > $message .= $var; > } > $details = $message > > The period and equal sign cause $message to prepend itself to $var. > This is the same thing as writing: > $message = $message."$var"; > > In either case, $message is preserved and added to on each loop. That > being the case, if you are puting this into an e-mail message, you > probably want to add line breaks after each line: > $message .= $var."\n"; > > Check out string operators: > http://www.php.net/manual/en/language.operators.string.php > and assignement operators: > http://www.php.net/manual/en/language.operators.assignment.php > > Good luck... > > Christopher Ostmo > a.k.a. tech@AppIdeas.com > AppIdeas.com > Meeting cutting edge dynamic > web site needs > > For a good time, > http://www.AppIdeas.com/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#55006) next »