php array help

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



LVL 3
3xtr3m3dAsked:
Who is Participating?
 
Rik-LeggerConnect With a Mentor Commented:
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
 
3xtr3m3dAuthor Commented:
Thanks a lot.

also is there way to skip a value from reading?
0
 
Rik-LeggerConnect With a Mentor Commented:
you could do something like this:

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

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.