Hi guys, I'm Alex. I'm a complete n00b to the world of PHP and am glad that y'all have support available here. :)

Anyway, I'm unofficially doing tech stuff for a magazine and I'm working on a code to order subscriptions. I'm having a problem with variables in a loop I'm using...

So I have a bunch of forms that are being generated from a loop, based on a number ($num) that a customer chooses (we're talking about shipping addresses). This form, with however many generated shipping addresses, is then sent through a payment processing script and upon verification (ideally), the script will send out $num of emails to our distributer containing the shipping information for each subscription.

I wrote the loop so the forms that it generates are called "Firstname1" and "Firstname2" for example.

My problem is, in writing the loop to be run post-positive-verification, can I have the PHP parse its own variables?

Something like this:

case "1":
    for($i = 0; $i < $num; $i++) { 
	mail ("Alex@worthwhilemag.com","Worthwhile Subscription Purchase",
"A Worthwhile Subscription has been ordered for: 
\n$firstname$i $lastname$i\n$address$i\n$city$i, $state$i $zip$i");
}

The double variables are what I feel is throwing me off. Anyone know if this is possible or I'm missing something?

I don't think I articulated this too well, btw...

hello alexruimy,

Try to use array

fpepito

try this example: http://www.fpepito.org/php/test3.php

<?

$customers = array(
  array("Firstname", "lastname", "address", "city", "state", "zip", "e-mail@hotmail.com", "url"),
  array("Francis", "Goncalves", "my adress", "Paris", "Ile-de-France", "75001", "test@hotmail.com", "http://ascejudo.mine.nu"),
  array("Francisco", "Goncalves Andrade", "my address", "Lisbon", "Estremedura", "60000", "test@hotmail.com", "http://www.fpepito.org/")
 );

#########

function read_customer($customers) {

  #read each Customer on the list of Customers
  while (list ($key, $customer) = each ($customers)) {
    echo "send e-mail to $customer[6]<BR>\n";
    echo "A Worthwhile Subscription has been ordered for: \n".$customer[0]." ".$customer[1]."\n".$customer[2]."\n".$customer[3].", ".$customer[4];
    echo "<HR>\n";
  }
}

read_customer($customers);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.