?
Solved

PHP next field

Posted on 2014-02-18
5
Medium Priority
?
354 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

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 111

Expert Comment

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

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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

764 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