Solved

eval() on indexed value

Posted on 2002-06-10
4
220 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 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

17 Experts available now in Live!

Get 1:1 Help Now