0
$results = mysqli_query($con,"SELECT * FROM dayalpha WHERE d_id= '".$_POST['dtb']."'");

echo "<table border='0'>
<tr>
<td>Day Name</td>
<td>Type</td>
<td>Alphabet</td>
</tr>";

while($row = mysqli_fetch_array($results))
 {
  echo "<tr>";
  echo "<td>" . $row['dayname'] . "</td>";
  echo "<td>" . $row['type'] . "</td>";
  echo "<td>" . $row['alpha'] ."</td>";
  echo "<td>" . $row['alpha1'] ."</td>";
  echo "<td>" . $row['alpha2'] ."</td>";
  echo "<td>" . $row['alpha3'] ."</td>";
  echo "<td>" . $row['alpha4'] ."</td>";
  echo "<td>" . $row['alpha5'] ."</td>";
  echo "<td>" . $row['alpha6'] ."</td>";
  echo "</tr>";
  }
echo "</table>";

在这里,我显示了我的 dayalpha 表中的字母。每个字母表都应该链接到 babyname 表中的多个 bname,只要 alpha == iname (即 name initial 存储在 babyname 表中)。

    -----------------
    My Babyname Table
    -----------------
    iname    bname    gender    mean

    K        Komal    Female    Tender
    K        Kiran    Male      Ray
    K        Kamlesh  Male      God
    N        Nityesh  Male      Yash

    -----------------
    My dayalpha table 
    -----------------
    dayname   type     alpha  alpha1  alpha2....
    Monday    vyainjan K      G       D
    Wednesday vyainjan T      D       N

如何将 dayalpha 中的值链接到 babyname 的多个值?

4

1 回答 1

0

如果您按原样保留表,则此 SQL 可能会起作用。

SELECT b.*
FROM babyname a
   INNER JOIN dayalpha b ON (a.iname = b.alpha OR a.iname = b.alpha2 OR a.iname = b.alpha3 ...)
WHERE b.dayname = 'Monday'

据我了解您的问题,这是正确的答案。

于 2013-04-02T02:04:14.747 回答