----------------------------------------------------------------------------
----------------- 
Disclaimer: The information contained in this email is intended only for the
use of the person(s) to whom it is addressed and may be confidential or
contain legally privileged information. If you are not the intended
recipient you are hereby notified that any perusal, use, distribution,
copying or disclosure is strictly prohibited. If you have received this
email in error please immediately advise us by return email at
[EMAIL PROTECTED] and delete the email document without making a
copy. 
----------------------------------------------------------------------------
-----------------

I've personally found that whenever you use "variable-variables" you a
probably better off using an array.

if you have 

$tag_num[1]  = 12345;
$tag_type[1] = "My Type of tag";
$tag_cost[1] = 1.23;
$tag_num[2]  = 98654;
$tag_type[2] = "Not my Type of tag";
$tag_cost[2] = 1.66;
$tag_num[3]  = 109876;
$tag_type[3] = "Unknown tag";
$tag_cost[3] = 1.77;

reset($tag_num);
while(list($key,$value) = each($tag_num)){
  $tag_cost[$key] = round($tag_cost[$key],2);
  echo "The KEY is $key and the VALUE is $value<br>\n";
  // Now do your SQL stuff
}

This is a bit messy because if you dont have a $tag_num it'll ignore
tag_type and $tag_cost. I prefere to use 2D arrays, im assuming the $tag_num
is some sort of unique identifier..

<?

$tag["12345"]["type"]  = "My type of Tag";
$tag["12345"]["cost"]  = "1.23";
$tag["98654"]["type"]  = "Not my type of Tag";
$tag["98654"]["cost"]  = "1.66";
$tag["109876"]["type"] = "Unknown Tag";
$tag["109876"]["cost"] = "1.77";

while(list($key,$data) = each($tag)){
  $data["cost"] = round($data["cost"],2);
  //$tag[$key]["cost"] = round($data["cost"],2); // This will modify the
original array, but not $data["cost"]
  echo "The tag is $key, the type is {$data['type']} and the cost is
{$data['cost']}<br>\n";
  //echo "The tag is $key, the type is $data[type] and the cost is
$data[cost]<br>\n"; // This will work but im not sure how correct it is.
  // Do your SQL thang
}
?>


These are very useful as you can unset($tag["109876"]) to get rid of data
and since you arent using a sequential for() loop you dont have to worry
about missing data.

This one comes down to taste though. I like the 2d arrays because they are
similiar to data sets from your db or a spreadsheet.

mn




Mark Nold
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
Senior Consultant
 
Change is inevitable, except from vending machines. 



-----Original Message-----
From: Asendorf, John [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 14, 2001 9:49 PM
To: Ignatius Teo; Asendorf, John; 'Darvin Andrioli'; 'Php-Windows
(E-mail)'
Subject: RE: [PHP-WIN] assigning variable names on the fly, backed
myself in to a corner


Well, here's what I came up with that finally worked for me:


for ( $i=1 ; $i <= $tag_count ; $i++ ) {  //tag_count came from the post
page

        $tag_num = "tag_num$i";
        $tag_type = "tag_type$i";
        $tag_cost = "tag_cost$i";
        if ( $$tag_cost == "" ) {    // can't have empty data per database
parameters
                $$tag_cost = "0.00";
        }
        $tag_late = "tag_late$i";
        if ( $$tag_late == "" ) {    // can't have empty data per database
parameters
                $$tag_late = "0.00";
        }
     
     $sql = "INSERT into cfull2.tbl_dl_tags (TAGID_NUM, CUSTID_NUM, TAG_NO,
TAG_YEAR, TYPE_CODE, COST, LATE) VALUES( $TAGID_NUM, $CUSTID_NUM,
${$tag_num}, $this_year, '${$tag_type}' , ${$tag_cost}, ${$tag_late} )";
     echo $sql;    //debug SQL
     $stmt = OCIParse ( $connection , $sql );
     OCIExecute ( $stmt , OCI_DEFAULT );
     OCICommit( $connection );
     OCIFreeStatement ( $stmt );
         
     $TAGID_NUM++;
}


John

---------------------
John Asendorf - [EMAIL PROTECTED]
Web Applications Developer
http://www.lcounty.com - NEW FEATURES ADDED DAILY!
Licking County, Ohio, USA
740-349-3631
Ipsa scientia potestas est


> -----Original Message-----
> From: Ignatius Teo [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 13, 2001 5:32 PM
> To: 'Asendorf, John'; 'Darvin Andrioli'; 'Ignatius Teo'; 'Php-Windows
> (E-mail)'
> Subject: RE: [PHP-WIN] assigning variable names on the fly, backed
> myself in to a corner
> 
> 
> No probs John. I'll take that in non-sequential small US 
> denominations, thanks! :-) And of course Darvin can have half.
> 
> Ignatius
> 
> > -----Original Message-----
> > From: Asendorf, John [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, 14 February 2001 00:33
> > To: Darvin Andrioli; 'Ignatius Teo'; Asendorf, John; 'Php-Windows
> > (E-mail)'
> > Subject: RE: [PHP-WIN] assigning variable names on the fly, backed
> > myself in to a corner
> > 
> > 
> > That's the ticket.  Thanks a million!
> > 
> > ---------------------
> > John Asendorf - [EMAIL PROTECTED]
> > Web Applications Developer
> > http://www.lcounty.com - NEW FEATURES ADDED DAILY!
> > Licking County, Ohio, USA
> > 740-349-3631
> > Ipsa scientia potestas est
> > 
> > 
> > > -----Original Message-----
> > > From: Darvin Andrioli [mailto:[EMAIL PROTECTED]]
> > > Sent: Tuesday, February 13, 2001 6:52 AM
> > > To: 'Ignatius Teo'; 'Asendorf, John'; 'Php-Windows (E-mail)'
> > > Subject: RE: [PHP-WIN] assigning variable names on the fly, backed
> > > myself in to a corner
> > > 
> > > 
> > > Ignatius wrote:
> > > 
> > > > try assigning it to another variable first:
> > > > for ....
> > > > $tag = "$tag_num$i";
> > > > $type = "tag_type$i";
> > > > $sql = .... VALUES (..., $tag, $type....);
> > > 
> > > The last statement must be:
> > > $sql = .... VALUES (..., $$tag, $$type....);
> > > 
> > > so you get the value of the variable named tag_type$i, 
> > > otherwise yo get only the string "tag_type value of $i"
> > > 
> > > Darvin
> > > 
> > > 
> > > > -----Original Message-----
> > > > From: Asendorf, John [mailto:[EMAIL PROTECTED]]
> > > > Sent: Tuesday, 13 February 2001 07:58
> > > > To: Php-Windows (E-mail)
> > > > Subject: [PHP-WIN] assigning variable names on the fly, 
> > > > backed myself in
> > > > to a corner
> > > > 
> > > > 
> > > > I've written a little script that makes a form using a simple 
> > > > for loop:
> > > > 
> > > > if ( $num_reg != "" )   {         //we're doing regulars
> > > > 
> > > >         for ( $i = 1 ; $i <= $num_reg ; $i++ )  {
> > > >                 echo "<tr><td>A<input type=\"hidden\" 
> > > > name=\"tag_type${i}\"
> > > > value=\"A\"></td>";
> > > >                 echo "<td><input type=\"text\" 
> > > > name=\"tag_num${i}\"></td>";
> > > >                 echo "<td><input type=\"text\" 
> name=\"tag_cost${i}\"
> > > > value=\"\"></td>";
> > > >                 echo "<td><input type=\"text\"
> > > > name=\"tag_late${i}\"></td></tr>\n";
> > > >         }       
> > > >         
> > > >         $tag_count = $num_reg;
> > > >         
> > > > }
> > > > 
> > > > Now what I have is a number of variables that look 
> > > something like this
> > > > 
> > > > $tag_type1, $tag_num1, $tag_cost1, $tag_late1, $tag_type2, 
> > > $tag_num2,
> > > > $tag_cost2, $tag_late2, etcetera... up to any number of tags...
> > > > 
> > > > now I'm trying to write a little for loop that drops this 
> > > > information into a
> > > > database after the POST:
> > > > 
> > > > for ( $i=1 ; $i <= $tag_count ; $i++ ) {  //tag_count came 
> > > > from the post
> > > > (dl_post_3.php)
> > > > 
> > > >      $sql = "INSERT into cfull2.tbl_dl_tags (TAGID_NUM, 
> > > > CUSTID_NUM, TAG_NO,
> > > > TAG_YEAR, TYPE_CODE, COST, TYPE) VALUES ($CUSTID_NUM, 
> > > > $tag_num$i, $tag_year,
> > > > '$tag_type$i' , $tag_cost$i )";
> > > > 
> > > >      $stmt = OCIParse ( $connection , $sql );
> > > > 
> > > >      OCIExecute ( $stmt , OCI_DEFAULT );
> > > >      OCICommit( $connection );
> > > >      OCIFreeStatement ( $stmt );
> > > > }
> > > > 
> > > > 
> > > > This obviously doesn't work and I'm not really sure what to 
> > > > do now.  Is this
> > > > a case of variable variable names?  I don't quite get those 
> > > either  :)
> > > > 
> > > > Thanks in advance all,
> > > > 
> > > > John
> > > > 
> > > > 
> > > > ---------------------
> > > > John Asendorf - [EMAIL PROTECTED]
> > > > Web Applications Developer
> > > > http://www.lcounty.com - NEW FEATURES ADDED DAILY!
> > > > Licking County, Ohio, USA
> > > > 740-349-3631
> > > > Ipsa scientia potestas est
> > > > 
> > > > 
> > > > -- 
> > > > PHP Windows Mailing List (http://www.php.net/)
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > To contact the list administrators, e-mail: 
> > > > [EMAIL PROTECTED]
> > > > 
> > > 
> > 
> > -- 
> > PHP Windows Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: 
> > [EMAIL PROTECTED]
> > 
> 

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to