Solved

PHP next field

Posted on 2014-02-18
5
329 Views
Last Modified: 2014-02-18
I use the code below to find certain fields:

***********
foreach ($_REQUEST as $theField => $Data){
      if (substr($theField,strlen($theField)-5,5) == "O~U~T"){
            if (is_numeric($Data * 1)){
                  if ($Data > 0){
                        echo $theField . " - " . $Data . "<br>";
                  }
            }
      }
}
***********
In my form, next to each O~U~T field is an I~N and S~O~L~D field.
I'd like to do something like this:
                        echo TheNextField . " - " . TheNextFieldsData . "<br>";
                        echo TheFieldAfterThat . " - " . TheNextFieldAfterThatData . "<br>";

How can I accomplish this please?
0
Comment
Question by:classnet
[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
  • 3
  • 2
5 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39867304
The foreach() statement contains two variables; these are the key and the data elements. Foreach is used to iterate over arrays and objects.  There are two kinds of array keys in PHP, index keys that are numeric and associative keys that are character strings.  The $_REQUEST superglobal variable is an associative array, so the keys are character strings.  That makes it difficult to use a numeric index to point to the "next" element of the array.

Here is what you might want to do:  Post a link to the web page that has the form, and post the actual PHP script that processes the form.  You can obscure passwords and such, but do not obscure any of the HTML or PHP code.  Armed with that information we may be able to help you get what you need.
0
 

Author Comment

by:classnet
ID: 39867321
Thanks... all I'm trying to do is to push this data into a db.  

The form contains, at least, many rows that have an O~U~T, I~N  and S~O~L~D column.

In one "insert" statement I want to push the three values.

This page is being converted from asp.  In asp the page referenced Request.Form.Item(intLoop).  intLoop checked for the O~U~T field

The sql statement used Request.Form.Item(intLoop), Request.Form.Item(intLoop + 1) and Request.Form.Item(intLoop + 3)
*NOTE Request.Form.Item(intLoop + 2) is a field that we don't need to push.

I am just trying to minimize the re-write...
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39867585
Thanks for the description.  Let me try this request again, please.
Post a link to the web page that has the form, and post the actual PHP script that processes the form.  You can obscure passwords and such, but do not obscure any of the HTML or PHP code.  Armed with that information we may be able to help you get what you need.
0
 

Author Closing Comment

by:classnet
ID: 39867724
Thanks for the assist... got it now.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39868275
Great - glad you've got it working.  Thanks for using EE, ~Ray
0

Featured Post

Independent Software Vendors: 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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
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 …

726 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