Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

eval() on indexed value

Posted on 2002-06-10
4
Medium Priority
?
231 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 200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

963 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