超链接SQL查询的第一个结果

时间:2014-07-16 21:54:19

标签: php html mysql

我希望添加一个指向此查询输出结果的链接。

<?php $tpw = "SELECT PLAYER, YEAR, WEEK, SUM(POINTS) ";
    $tpw .= " FROM SCHEDULE";
    $tpw .= " WHERE OWNER = 'BRANDON' ";
    $tpw .= " GROUP BY YEAR, WEEK, PLAYER ";
    $tpw .= " ORDER BY SUM(POINTS) DESC ";
    $tpw .= " LIMIT 5";
    $tpwresult = mysqli_query($con, $tpw);
    //test for query error
    if (!$tpwresult){
        die("Database Query Failed!");
    }?>


    <table class="weeks">
    <th colspan="4">Most Points in a Week (Player)</th>
    <tr><td>Year</td><td>Week</td><td>Player</td><td>Points</td></tr>
        <?php while($tpwrow = mysqli_fetch_assoc($tpwresult)){?>
    <tr><td><?php echo $tpwrow ["YEAR"];?></td>
    <td><?php echo $tpwrow ["WEEK"];?></td>
    <td><?php echo $tpwrow ["PLAYER"];?></td>
    <td><?php echo $tpwrow ["SUM(POINTS)"];?></td></tr>
<?php } ?></table>

是否可以仅超链接此表的第一行/结果?

1 个答案:

答案 0 :(得分:0)

不是最有效的代码,但保持简单

<table class="weeks">
<th colspan="4">Most Points in a Week (Player)</th>
<tr><td>Year</td><td>Week</td><td>Player</td><td>Points</td></tr>
    <?php $first=1
    while($tpwrow = mysqli_fetch_assoc($tpwresult)){?>
<tr><td><?php echo $tpwrow ["YEAR"];?></td>
<td><?php echo $tpwrow ["WEEK"];?></td>

<td>
<?php if ($first == 1) }?>
<a href='http://www.youtube.com/watch?v=qiZXjcb77Qw'>
<?php }?>
<?php echo $tpwrow ["PLAYER"];?>
<?php if ($first == 1) {?>
</a>
<?php $first = 0;}?>
</td>
<td><?php echo $tpwrow ["SUM(POINTS)"];?></td></tr>
<?php } ?></table>