Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用匹配两个表(mysql)id的php while循环将类添加到表行中_Php_Mysql_Sql - Fatal编程技术网

使用匹配两个表(mysql)id的php while循环将类添加到表行中

使用匹配两个表(mysql)id的php while循环将类添加到表行中,php,mysql,sql,Php,Mysql,Sql,我有一个userkeywords表,它是这样的: ukid cdid kid 14 28 57 15 28 56 16 28 55 17 28 48 18 28 28 19 19 57 20 25 56 21 25 57 现在我通过以下查询得到哪个cdid有kid的编号: $query2 = mysql_query("SE

我有一个
userkeywords
表,它是这样的:

ukid    cdid    kid
14      28      57
15      28      56
16      28      55
17      28      48
18      28      28
19      19      57
20      25      56
21      25      57
现在我通过以下查询得到哪个
cdid
kid
的编号:

$query2 =  mysql_query("SELECT kid FROM userkeywords WHERE cdid = '$cdid'");
$result2 =  mysql_fetch_array($query2);
$eKid = $result2['kid'] . "<br/>";
现在,我用下面的代码从
keywords
表中获取所有关键字,我想添加一个类,使
keywords
kid
userkeywords
kid
匹配

<?php
echo "<div id='keywordBox'>";
echo '<table border="0" cellpadding="0" cellspacing="0" width="1055">';
$count = 0;
while($result =  mysql_fetch_array($query)){
  if($count%6==0 && $count!=0){    
    echo '</tr><tr>';
  }elseif($count==0) echo '<tr>';

    $kid = $result['kid'];
    $keywordName = ucfirst($result['keywordName']);     

    $keyword_short_name = ucfirst($result['keyword_short_name']); 
    $keyword_full_name = ucfirst($result['keyword_full_name']); 

    if($eKid === $kid){
        $class = "keywordHigligh";  
    }

    echo "<input type='hidden' id='kid' value='$kid'/>";    
    echo "<input type='hidden' id='cdid' value='$cdid'/>";  
    echo "<td width='400' onclick='keywordclick($kid,$cdid)' class='$class'><strong>$keyword_full_name</strong><strong> ($keyword_short_name)</strong><br/>$keywordName</td>";
    $count++;  
    }   
echo '</table>';
echo "</div";
?>


现在我不知道我需要把
$query2
放在哪里,或者我怎样才能在表行中添加一个与mysql表
kid
匹配的类?

在if条件下尝试删除一个额外的
=
,我想这会解决您的问题
如果($eKid==$kid){$class=“keywordHigligh”}
让我试试,但我把$query2放在哪里?我试过了,但没有解决。$query2应该在while loop上面。如果我在while loop上面使用$query2,那么我只能得到一个
kid
,但用户可能只有很少的
kid
<?php
echo "<div id='keywordBox'>";
echo '<table border="0" cellpadding="0" cellspacing="0" width="1055">';
$count = 0;
while($result =  mysql_fetch_array($query)){
  if($count%6==0 && $count!=0){    
    echo '</tr><tr>';
  }elseif($count==0) echo '<tr>';

    $kid = $result['kid'];
    $keywordName = ucfirst($result['keywordName']);     

    $keyword_short_name = ucfirst($result['keyword_short_name']); 
    $keyword_full_name = ucfirst($result['keyword_full_name']); 

    if($eKid === $kid){
        $class = "keywordHigligh";  
    }

    echo "<input type='hidden' id='kid' value='$kid'/>";    
    echo "<input type='hidden' id='cdid' value='$cdid'/>";  
    echo "<td width='400' onclick='keywordclick($kid,$cdid)' class='$class'><strong>$keyword_full_name</strong><strong> ($keyword_short_name)</strong><br/>$keywordName</td>";
    $count++;  
    }   
echo '</table>';
echo "</div";
?>