MySql关系数据库混淆

时间:2017-06-21 23:43:55

标签: php mysql relational-database

我一直在尝试使用PHP来显示MySql NOTES表中与QUOTES表中特定NAME匹配的所有结果。目标是我想显示每个特定名称下列出的所有评论。

QUOTES表格列:ID / NAME / EMAIL / PRICE

注意表列:ID / NAME / AGENT / DATE / COMMENTS

这是我正在使用的MySql代码:

mysql_select_db($database_dbConnect, $dbConnect);
$query_rsquotes = "SELECT * FROM quotes ORDER BY `id` DESC";
$rsquotes = mysql_query($query_rsquotes, $dbConnect) or die(mysql_error());
$row_rsquotes = mysql_fetch_assoc($rsquotes);
$totalRows_rsquotes = mysql_num_rows($rsquotes);

mysql_select_db($database_dbConnect, $dbConnect);
$query_rsnotes = "SELECT quotes.*, notes.* FROM quotes INNER JOIN notes ON quotes.name = notes.name ORDER BY notes.date DESC";
$rsnotes = mysql_query($query_rsnotes, $dbConnect) or die(mysql_error());
$row_rsnotes = mysql_fetch_assoc($rsnotes);
$totalRows_rsnotes = mysql_num_rows($rsnotes);

然后显示结果:

<?php do { ?>
    <?php echo $row_rsquotes['name']; ?>
    <?php echo $row_rsquotes['email']; ?>

<?php
    if ($row_rsquotes['name'] == $row_rsnotes['name']) {
        do {
            if ($row_rsquotes['name'] == $row_rsnotes['name']) {
                echo "<div class='agentNotes'><p><strong>DATE: </strong><span class='meta-date'>" . $row_rsnotes['date'] . "</span></p><p><strong>AGENT:</strong> " . $row_rsnotes['agent'] . "</p><p><strong>AGENT NOTES:</strong> " . $row_rsnotes['comments'] . "</p></div>";
             }
        } while ($row_rsnotes = mysql_fetch_assoc($rsnotes));
    }
?>

<?php } while ($row_rsquotes = mysql_fetch_assoc($rsquotes)); ?>

它循环显示该特定NAME的匹配记录,但是当它到达下一个NAME时,它不会显示匹配的COMMENTS。我做错了什么?

1 个答案:

答案 0 :(得分:0)

 while(fgets(line, sizeof(line), f)) {
            token[0] = strtok(line, sep_list);
            listaProiecte[i].id = atoi(token[0]);


            first = inserareNod(first, listaProiecte[i]);
            i++;
        }