Solved

eval() on indexed value

Posted on 2002-06-10
4
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
The viewer will learn how to dynamically set the form action using jQuery.

751 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