Zado
asked on
Problem with php 'for' loop
Hi,
I have a script like so:
There's 4 'NC's per line, so normally if I replace all the 'NC' with 'for' loop element (e.g. $i), it wouldn't work, because in one line there will be NC1, NC2, NC3, NC4, and next line NC5, NC6 etc.
I want to have each NC to be NC1 in first line, NC2 in second line and so on, basically same as in php code above. I hope it's clear.
Thanks for any help.
I have a script like so:
<?php
if ($_POST['NC1']=='Prefix') {$NC1 = 'xx';} else $NC1 = $_POST['NC1'];
if ($_POST['NC2']=='Chart number') {$NC2 = 'xx';} else $NC2 = $_POST['NC2'];
if ($_POST['NC3']=='Suffix') {$NC3 = 'xx';} else $NC3 = $_POST['NC3'];
if ($_POST['NC4']=='International number') {$NC4 = 'xx';} else $NC4 = $_POST['NC4'];
if ($_POST['NC5']=='Class') {$NC5 = 'xx';} else $NC5 = $_POST['NC5'];
if ($_POST['NC6']=='P,PandA,n/a') {$NC6 = 'xx';} else $NC6 = $_POST['NC6'];
if ($_POST['NC7']=='BA folio number') {$NC7 = 'xx';} else $NC7 = $_POST['NC7'];
if ($_POST['NC8']=='ARCS on cd') {$NC8 = 'xx';} else $NC8 = $_POST['NC8'];
if ($_POST['NC9']=='ARCS region') {$NC9 = 'xx';} else $NC9 = $_POST['NC9'];
if ($_POST['NC10']=='Chart title') {$NC10 = 'xx';} else $NC10 = $_POST['NC10'];
...
?>
But the thing is, I have over 100 lines like those above, so it's up to ($_POST['NC150']), I want to use 'for' loop here to make it easier, but not sure how to do that.There's 4 'NC's per line, so normally if I replace all the 'NC' with 'for' loop element (e.g. $i), it wouldn't work, because in one line there will be NC1, NC2, NC3, NC4, and next line NC5, NC6 etc.
I want to have each NC to be NC1 in first line, NC2 in second line and so on, basically same as in php code above. I hope it's clear.
Thanks for any help.
ASKER
Could you help me to apply your idea into my code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
>> if ( $NC['NC'.$l] = $check['CC' . $l] )
should be ==:
if ( $NC['NC'.$l] == $check['CC' . $l] )
Full credit to angelIII
should be ==:
if ( $NC['NC'.$l] == $check['CC' . $l] )
Full credit to angelIII
indeed ! thanks for the correction
${NC . $loop} = $_POST["NC" . $loop];
in the end, you still have 150 variables instead of having 1 array ...
please rethink about that.
apart from that, you will need an array (indexed with the same "number" that holds the string to compare the $_POST value too, to make the loop "generic".
hope this helps