How to compare two arrays during a condition

Here is my code

<tr>
    <th width="100"><strong><?php echo $isian2; ?></strong></th>
    <th width="140"><strong><?php echo $isian3; ?></strong></th>
    <td width="10" align="center"><strong>Option</strong></td>
  </tr>

<?php

$pageSql = "SELECT * FROM tcar";
            $pageQry = mysql_query($pageSql, $db) or die ("error paging: ".mysql_error());
            $kolomLain = mysql_fetch_array($pageQry);

 $mySql = "SELECT * FROM tcustomer ";
        $myQry = mysql_query($mySql, $db) or die ("error paging: ".mysql_error());
        $kolomData = mysql_fetch_array($myQry);

    while ($kolomData = mysql_fetch_array($myQry)) {
     <tr>
        <td> <?php echo $kolomData['id']; ?> </td>
        <td> <?php echo $kolomData['kd']; ?> </td>
?>

<?php

    if ($kolomData['kd']==$kolomLain['kd']){
    echo "<td class='cc' align='center'> A </td>     
 ";
    }
    else {
    echo "  <td class='cc' align='center'> B </td> 
     ";
  }
?>

      

If the code doesn't work, it can only be compared to the first "kd" field in the tcar table.

I'm sorry if he already asks another, but in fact I tried to search but still couldn't get the result.

+3


source to share


2 answers


change the PHP code segment to



$sql1 = "SELECT * FROM tcar";
$res1 = mysql_query($sql1, $db) or die ("error paging: ".mysql_error());
$kolomLainSize = mysql_num_rows($res1);

$sql2 = "SELECT * FROM tcustomer ";
$res2 = mysql_query($sql2, $db) or die ("error paging: ".mysql_error());
$kolomDataSize = mysql_num_rows($res2);

for($i = 0; $i < min($kolomLainSize, $kolomDataSize); $i++)
{
    $kolomLain = mysql_fetch_array($res1);
    $kolomData = mysql_fetch_array($res2);
    // print your data here
}
if($i == $kolomLainSize)
{
    // no more $kolomLain, but there are still some $kolomData
    while($kolomData = mysql_fetch_array($res2))
    {
        // print your data
    }
}
else
{
    // no more $kolomData, but there are still some $kolomLain
    while($kolomLain = mysql_fetch_array($res1))
    {
        // print your data
    }
}

      

+2


source


Try it twice and put the string result in two different values. After comparing this.



0


source







All Articles