Jump to content

Learning Arrays


maliary

Recommended Posts

 

 

Ok,

 

 

I have the following code below. $piod is an array containing elements and the if statement is supposed to act depending on the elements in the array. The problem is it dosen't loop. When i echo $piod[$j] nothing gets outputted.

 

sample of $piod=array ('praden','draden')

 


          if ($_SESSION['perform'] == 1) {      
       for ($j = 0; $j <2; $j++) {
       if ($parameterselect == $piod[$j]) {  
                 
           # first column
    echo '<td';
    echo ' bgcolor="#ffffee" class="a10_b"><nobr> <b>';
    echo  $nval[$j];
    echo '</b> </nobr>';
    echo '</td>';
    echo  $piod[$j];
    echo "<td><nobr> <input name=name".$counterup." type=hidden size=8 value=$nval[$j]> </nobr></td>"; 
    echo "<td class=a10_b><input name=test_value".$counterup." type=text size=8 value=$pval[$j]> </td>";
    echo "<td><nobr> <input name=msr_unit".$counterup." type=hidden size=7 value=$ms_r[$j]> </nobr></td>";
    echo "<td><nobr> <input name=ranges".$counterup." type=hidden size=7 value= $rval[$j]> </nobr></td>";             
   
        $counterup++;


     
       }

 

Link to comment
https://forums.phpfreaks.com/topic/55081-learning-arrays/#findComment-272969
Share on other sites

hi,

 

Please check this

 

In the above code  (if ($parameterselect == $piod[$j]) {  ) is wrong,

Before the if loop select the variable $parameterselect then only the loop will execute.

 

<?

$parameterselect='draden';

$piod=array ('praden','draden');

 

//if ($_SESSION['perform'] == 1) {     

      for ($j = 0; $j <2; $j++) {

      if ($parameterselect == $piod[$j]) { 

               

          # first column

    echo '<td';

    echo ' bgcolor="#ffffee" class="a10_b"><nobr> <b>';

    echo  $nval[$j];

    echo '</b> </nobr>';

    echo '</td>';

    echo  $piod[$j];

    echo "<td><nobr> <input name=name".$counterup." type=hidden size=8 value=$nval[$j]> </nobr></td>";

    echo "<td class=a10_b><input name=test_value".$counterup." type=text size=8 value=$pval[$j]> </td>";

    echo "<td><nobr> <input name=msr_unit".$counterup." type=hidden size=7 value=$ms_r[$j]> </nobr></td>";

    echo "<td><nobr> <input name=ranges".$counterup." type=hidden size=7 value= $rval[$j]> </nobr></td>";           

 

        $counterup++;

 

 

  }}

    //  }

 

R u able to understand this?

Link to comment
https://forums.phpfreaks.com/topic/55081-learning-arrays/#findComment-272971
Share on other sites

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.