Solved

eval() on indexed value

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php construct 5 26
echo paypal data on screen 5 50
000webhost.com default error log 1 28
Change background color in td if any value is 1 9 12
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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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