[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

php array help

Posted on 2011-04-19
3
Medium Priority
?
251 Views
Last Modified: 2012-05-11
Hi

$tblcategory = 'cat_code,cat_description,user,stamp,ip';  //table field order
$expectedFields = 'id,cat_description'; //form fields

$tblorder = explode(',', $tblcategory);
$expectedorder = explode(',', $expectedFields);

im reading values like below

foreach ($tblorder as $data){            
            $result[$data]= $_GET[$data];      
}

im getting primary key always as id and but primary key of this table is cat_code

so how to read id value as cat_code and assign that to result array?


hope someone will understand what i meant

Thanks



0
Comment
Question by:3xtr3m3d
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 2000 total points
ID: 35426583
Maybe this will help you:

<?php 

// Table fields including form fields
$aTable = array(
	'cat_code' => 'id',
	'cat_description' => 'cat_description',
	'user',
	'stamp',
	'ip',
);


foreach ($aTable as $sKey => $sValue){            
            $result[$sValue]= $_GET[$sKey];      
}

?>

Open in new window

0
 
LVL 3

Author Comment

by:3xtr3m3d
ID: 35426945
Thanks a lot.

also is there way to skip a value from reading?
0
 
LVL 8

Assisted Solution

by:Rik-Legger
Rik-Legger earned 2000 total points
ID: 35426981
you could do something like this:

foreach ($aTable as $sKey => $sValue){  
            if ($sValue == 'something') {
                        continue;
            }          
            $result[$sValue]= $_GET[$sKey];      
}

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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 article discusses how to implement server side field validation and display customized error messages to the client.
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
Course of the Month20 days, 9 hours left to enroll

867 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