Solved

eval() on indexed value

Posted on 2002-06-10
4
221 Views
Last Modified: 2011-09-20
I have a form that submits multiple hidden fields. Part of this form submits a field called  $Orderline1 (40 total -  $Orderline1 - $Orderline401). I'm trying to determine how many fields have data but I keep getting errors with my eval!

I have tried:

$cnt = 1;
$orders = 1;
     while ($orders){
          eval("if($OrderLine"+$cnt+" != '')"){
          echo $cnt;
          }else{ $orders = 0;}
          $cnt++;
     }

//////////////////////////////////////////////////

I have also tried the eval line as:

if(eval("$OrderLine"+$cnt) != ""){

But I can't get the eval to work! Is this the best way to figure out how many fields have data and if so what is the eval statement. If not then what is the best way?
0
Comment
Question by:sargento
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 7068105
Duplicate! Delete this question
0
 

Author Comment

by:sargento
ID: 7068141
Duplicated question 3 time?
0
 
LVL 32

Expert Comment

by:Batalf
ID: 7068156
3 equals question. I have made a suggestion on how to solve your problem in one of them. The other ones should be deleted.
0
 
LVL 5

Accepted Solution

by:
Hamlet081299 earned 50 total points
ID: 7069063
You really don't need to use eval at all for this.

You would find it much easier using variable variables...

$cnt = 1;
$orders = 1;
    while ($orders){
         $varname = OrderLine . $cnt;
         if(!empty($$varname)){
         echo $cnt;
         }else{ $orders = 0;}
         $cnt++;
    }

Also note that '+' is for arithmetic addition, for string concatenation, use ".".
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now