duansao20000508 2017-04-05 15:43
浏览 35
已采纳

将MySql数据从PHP打印到HTML工具提示

So I am new to programming with MySql and PHP so I am not sure how to parse the data from a PHP script to an HTML tooltip.

Here is my PHP:

<?php
$servername = "server";
$username = "username";
$password = "password";
$dbname = "dbname";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "select courseCode, courseName from building b, room r, occupy o, timeslot t, meet m, section s, course c, timespan ts, day d, class cl where b.name = 'BH' and r.roomNum = '128' and b.buildingID = r.buildingID and o.roomID = r.roomID and t.timeID = o.timeID and t.timeID = m.timeID and m.sectionID = s.sectionID and c.courseID = s.courseID and t.spanID = ts.spanID and ts.start = '10:05' and ts.end = '11:25' and t.dayID = d.dayID and d.dayOfWeek = 'M' and cl.roomID = r.roomID and cl.sectionID = s.sectionID";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    echo "Course Code: " . $row["courseCode"]. " - Name: " . $row["courseName"]."<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>

Ultimately I would like to place the selected data into a tooltip I have placed on a list item where it says title="". Any suggestions?

HTML:

<div class="list-group">
        <a class="list-group-item list-group-item-action list-group-item-success listmargin"><abbr title="" rel="tooltip">HH 201</abbr></a>
        <a class="list-group-item list-group-item-action list-group-item-success listmargin"><abbr title="From DB </em>." rel="tooltip">HH 203</abbr></a>
  • 写回答

1条回答 默认 最新

  • doulu2011 2017-04-05 15:49
    关注

    Just like you already did.

    <?php
    $output = '';
    while ($row = $result->fetch_assoc()):
        // escape data
        $courseCode = htmlspecialchars($row['courseCode']);
        $courseName = htmlspecialchars($row['courseName']);
    
        $output .= sprintf('<a class="list-group-item list-group-item-action list-group-item-success listmargin"><abbr title="%s" rel="tooltip">%s</abbr></a>', $courseName, $courseCode);
    endwhile;
    ?>
    <div class="list-group">
        <?= $output ?>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题