2017-04-05 3 views
0

So bin ich neu in der Programmierung mit MySql und PHP, so bin ich nicht sicher, wie Sie die Daten von einem PHP-Skript zu einem HTML-Tooltip analysieren.Drucken von MySql Daten von PHP zu HTML Tooltip

Hier ist meine 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(); 
?> 

Schließlich würde Ich mag die ausgewählten Daten in einem Tooltip platzieren ich auf ein Listenelement gesetzt haben, wo es heißt title = „“. Irgendwelche Vorschläge?

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> 

Antwort

0

Genau wie Sie bereits getan haben.

<?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> 
+0

Also verwenden Sie diesen PHP-Code getrennt von dem anderen PHP-Code, den ich habe? Momentan rufe ich den PHP-Code im Kopf aus einer separaten PHP-Datei und versuche, ihn in der Listengruppe anzuwenden. – Christian

+0

Ich habe meine Antwort aktualisiert. Hoffe ich habe dich richtig verstanden. – Mary