Jump to content

Arrays


maliary

Recommended Posts

Hello there,

 

I've got a logic problem over here that needs to be checked out.

 

$deps = $db->Execute("SELECT * FROM $dbtable WHERE job_id='$batch_nr' AND group_id='$rowb[group_id]'" );               

            while($rowz = $deps->FetchRow())

            {

                    // get the test group

                  $pio =  $rowz['group_id'];

               

 

                    // get the test data values and the test param name

                  $test_vals =  $rowz['serial_value'];

                  $values = preg_split ("/[\&]+/", "$test_vals");

                  array_shift($values);

             

 

                  $new_strs = implode("=", $values);

                  $vals = preg_split ("/[\=]+/", "$new_strs");

                  array_shift($vals);

           

 

                 

                  $numitems2 = count($vals);

                  $notes = $rowz['notes'];

   

                   

                 

                for ($col=0; $col <$numitems2; $col+=2){

                        $fname2 =$fname2.$vals[$col].'#';       

                }

               

                for ($rol=1; $rol <$numitems2; $rol+=2){           

                        $rname2 = $rname2.$vals[$rol].'#';       

                }   

            }

         

            $counterup=0;

         

            // Obtains the nr values here

              $nval2 = preg_split ("/[\#]+/", "$fname2");

              array_pop($nval2);

           

         

         

         

            $jack = 285285; 

            $numname = count($nval2);

            $rvalues = str_replace( "-", 285285, "$rname2");

            $rvals = preg_split ("/[\#]+/", " $rvalues");

         

 

   

            $disp = $db->Execute("SELECT  * FROM $table WHERE  group_id='$rowb[group_id]' ORDER by torder");

            while($rows3 = $disp->FetchRow())             

            {

           

                               

          if ($rows3['nr'] == $nval2[$counterup])

            {

            if ($rvals[$counterup] != $jack)

       

        {

                $cache .= '<tr class=wardlistrow1';

                $cache .= '>';

                $cache.='<td class=va12_n > '.$rows3['name'].' </td>'."\n";

                $cache.= "<td width=149 valign=top class=va12_n > $rvals[$counterup] </td>";

                $cache.='<td class=va12_n> '.$row3['msr_unit'].'</td>'."\n";

                $cache.='<td width="149" valign="top" class=va12_n> '.$rows3['normals'].' </td>'."\n";

             

                 

                $cache .= '</tr>';

 

        } 

                 

               

            }

            $counterup++;

           

          } 

       

           

              $cache .= '<tr><td width="160" height="10"></td> </tr>';

          }

 

 

echo $cache;

 

 

 

 

 

the two arrays $rows3['nr'] and $nval2[$counterup] need to match up to display the data in between the if brackets. The problem is they cannot match up unless they are exactly of the same order. But this is not possible as the data needs to be printed out in torder.$nval2[$counterup] should not neccesarily be in torder and torder can change.

 

So the question is, Is it possible to match them up while respecting the torder and still out put the data btwn the brackets correctly?

 

take this as sample :

 

$rows3['nr'] = '125','136','143','148','149','159','160','161','191','201','205','212','221','247','251','253','254','255','327','256','239','262','257','337','338','339','340'

 

$nval2[$counterup] = '125','136','143','148','149','159','160','161','191','201','205','212','221','247','251','253','254','255','256','239','262','257'

Link to comment
Share on other sites

I'm not 100% sure what you are doing or what you are trying to accomplish. I *think* you are just trying to find the records where the value of the 'nr' column is in the list $nval2.

 

If that is the case, then you just need to modify your query such that it only pulls those records to begin with. Much simpler and elegant solution.

 

Change this:

$disp = $db->Execute("SELECT  * FROM $table WHERE  group_id='$rowb[group_id]' ORDER by torder");

 

To this:

$query = "SELECT * 
          FROM $table
          WHERE  group_id='$rowb[group_id]'
            AND nr in ('".implode("','",$nval2)."')
          ORDER by torder";
$disp = $db->Execute($query);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.