Jump to content

Logic for this functionality in PHP


liam1412

Recommended Posts

Hi there people.

 

My head doesn't seem to be working today I'm wondering if someone could help me

 

at least with Psuedo code

 

I have the following data collected from a form.

 

 

PHP Code:
$set_warehouse_id = $_POST['warehouse_id'];
$set_dam_location = sanitizeInput($_POST['location']);
$set_location_empty = $_POST['location_empty'];
$set_no_positions = sanitizeInput($_POST['num_positions_affected']);
$set_reported_by = $_SESSION['ses_userid'];
$set_reported_time = $timenow;
$set_report_comment = sanitizeInput($_POST['comments']);

$damage_level_1 = $_POST['damage_level_1'];
$action_1 = santizeInput($_POST['action_1'];
$completed_1 = $_POST['completed_1'];
$comp_req_1 = sanitizeInput($_POST['comp_req_1']);
$comp_cost_1 = $_POST['comp_cost_1'];
$cost_1 = $_POST['cost_1'];

$damage_level_2 = $_POST['damage_level_2'];
$action_2 = santizeInput($_POST['action_2'];
$completed_2 = $_POST['completed_2'];
$comp_req_2 = sanitizeInput($_POST['comp_req_2']);
$comp_cost_2 = $_POST['comp_cost_2'];
$cost_2 = $_POST['cost_2'];

$damage_level_3 = $_POST['damage_level_3'];
$action_3 = santizeInput($_POST['action_3'];
$completed_3 = $_POST['completed_3'];
$comp_req_3 = sanitizeInput($_POST['comp_req_3']);
$comp_cost_3 = $_POST['comp_cost_3'];
$cost_3 = $_POST['cost_3'];

$damage_level_4 = $_POST['damage_level_4'];
$action_4 = santizeInput($_POST['action_4'];
$completed_4 = $_POST['completed_4'];
$comp_req_4 = sanitizeInput($_POST['comp_req_4']);
$comp_cost_4 = $_POST['comp_cost_4'];
$cost_4 = $_POST['cost_4'];

$damage_level_5 = $_POST['damage_level_5'];
$action_5 = santizeInput($_POST['action_5'];
$completed_5 = $_POST['completed_5'];
$comp_req_5 = sanitizeInput($_POST['comp_req_5']);
$comp_cost_5 = $_POST['comp_cost_5'];
$cost_5 = $_POST['cost_5'];

$damage_level_6 = $_POST['damage_level_6'];
$action_6 = santizeInput($_POST['action_6'];
$completed_6 = $_POST['completed_6'];
$comp_req_6 = sanitizeInput($_POST['comp_req_6']);
$comp_cost_6 = $_POST['comp_cost_6'];
$cost_6 = $_POST['cost_6'];

$damage_level_7 = $_POST['damage_level_7'];
$action_7 = santizeInput($_POST['action_7'];
$completed_7 = $_POST['completed_7'];
$comp_req_7 = sanitizeInput($_POST['comp_req_7']);
$comp_cost_7 = $_POST['comp_cost_7'];
$cost_7 = $_POST['cost_7'];

$damage_level_8 = $_POST['damage_level_8'];
$action_8 = santizeInput($_POST['action_8'];
$completed_8 = $_POST['completed_8'];
$comp_req_8 = sanitizeInput($_POST['comp_req_8']);
$comp_cost_8 = $_POST['comp_cost_8'];
$cost_8 = $_POST['cost_8'];

$damage_level_9 = $_POST['damage_level_9'];
$action_9 = santizeInput($_POST['action_9'];
$completed_9 = $_POST['completed_9'];
$comp_req_9 = sanitizeInput($_POST['comp_req_9']);
$comp_cost_9 = $_POST['comp_cost_9'];
$cost_9 = $_POST['cost_9'];

$damage_level_10 = $_POST['damage_level_10'];
$action_10 = santizeInput($_POST['action_10'];
$completed_10 = $_POST['completed_10'];
$comp_req_10 = sanitizeInput($_POST['comp_req_10']);
$comp_cost_10 = $_POST['comp_cost_10'];
$cost_10 = $_POST['cost_10'];

$damage_level_11 = $_POST['damage_level_11'];
$action_11 = santizeInput($_POST['action_11'];
$completed_11 = $_POST['completed_11'];
$comp_req_11 = sanitizeInput($_POST['comp_req_11']);
$comp_cost_11 = $_POST['comp_cost_11'];
$cost_11 = $_POST['cost_11'];

$damage_level_12 = $_POST['damage_level_12'];
$action_12 = santizeInput($_POST['action_12'];
$completed_12 = $_POST['completed_12'];
$comp_req_12 = sanitizeInput($_POST['comp_req_12']);
$comp_cost_12 = $_POST['comp_cost_12'];
$cost_12 = $_POST['cost_12'];

$damage_level_13 = $_POST['damage_level_13'];
$action_13 = santizeInput($_POST['action_13'];
$completed_13 = $_POST['completed_13'];
$comp_req_13 = sanitizeInput($_POST['comp_req_13']);
$comp_cost_13 = $_POST['comp_cost_13'];
$cost_13 = $_POST['cost_13'];

$damage_level_14 = $_POST['damage_level_14'];
$action_14 = santizeInput($_POST['action_14'];
$completed_14 = $_POST['completed_14'];
$comp_req_14 = sanitizeInput($_POST['comp_req_14']);
$comp_cost_14 = $_POST['comp_cost_14'];
$cost_14 = $_POST['cost_14'];  

 

Is there any easy way to check if the values of action_*, comp_req_*, and comp_cost_* and cost_* are empty in each group, without haveing to resort to a checking each of the 4 fields in each of the 14 groups.

 

Basically if the 4 fields are empty I want to ignore the entire group and move on the next to perform checking and insert in DB

 

If it makes things easier I actually use a mysql db to generate all these form fields by having a table with a list of each item (item_no,item_name)

 

then a use a while loop from the db

 

ie

 

while($getdbshizny)

{

 

//create that particular group of fields.

 

}

 

Maybe when submitting the form I could put all the results in an array, but I wouldn't have a clue what to do with it after that. My head hurts.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/171140-logic-for-this-functionality-in-php/
Share on other sites

I really don't want to write it out for you so I'll just give you a simple example. (I'll look for plums and apples)

 

$a = array(
  'pear_1' => 'foo',
  'apple_1' => 'foo',
  'plum_1' => 'foo',
  'orange_1' => 'foo',
  'pear_2' => 'foo',
  'apple_2' => 'foo',
  'plum_2' => 'foo',
  'orange_2' => 'foo'
);
foreach($a as $key => $val) {
  if (substr($k, 0, 3) == 'plum' || substr($k, 0, 4) == 'apple' && !empty($v) {
    // process
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.