组合2 SQL表

时间:2017-01-17 13:41:49

标签: php mysql

<?php
$mysqli = mysqli_connect***;

$result = mysqli_query($mysqli, 'SELECT * FROM componnets LEFT JOIN fill ON componnets.id=fill.Uid') or die(mysqli_error(mysqli));
$resultCOM = mysqli_query($mysqli, 'SELECT * FROM componnets') or die(mysqli_error(mysqli));

while ($rowCOM = mysqli_fetch_array($resultCOM)) {
    echo "<input type='hidden' name='compo' value='".$rowCOM['compon']."'>".$rowCOM['compon']."";
    echo "<select name='fill'>";

    while ($row = mysqli_fetch_array($result)) {    
        echo "<option value='".$row['num']."'>".$row['num']."</option>";
    }
    echo "</select>";
}

// Free result set
mysqli_free_result($result);
/* close connection */
$mysqli->close();
?>

问题是这个,我需要在2个sql之间结合 我需要的结果是:

&#13;
&#13;
<input type='hidden' name='compo' value='decod'>decod
<select name='fill'><option value='100'>100</option>
</select>
<input type='hidden' name='compo' value='rg5.9'>rg5.9
<select name='fill'><option value='100'>100</option>
<select name='fill'><option value='100'>200</option>
<select name='fill'><option value='100'>300</option>
</select>
&#13;
&#13;
&#13;

我尝试所有组合而没有...

现在的输出就像这样

&#13;
&#13;
<input type='hidden' name='compo' value='decod'>decod
</select>
<input type='hidden' name='compo' value='rg5.9'>rg5.9
<select name='fill'><option value='100'>100</option>
<select name='fill'><option value='100'>300</option>
</select>
&#13;
&#13;
&#13;

mysql就像这样

fill - num uid 
       100   3
       300   1

componnets - id  compon
             1    decod
             2    rg59
             3    rg6

请求帮助。

0 个答案:

没有答案