1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<?php
//query the database
$myResult = mysql_query('SELECT ref_links.*, ref_categories.category_name FROM ref_links, ref_categories WHERE ref_links.ref_categories_id=ref_categories.id', $connectID)
or die ("Unable to select from database");
//loop through the returned records
print '<table border="1">'."\n";
while ($row = mysql_fetch_array($myResult, MYSQL_ASSOC)) {
//category heading only written out if a listing is in diff cat from previous listing
//$thisCat is used to test if a new heading needs to be written out
$thisCat= $row['category_name'];
if ($lastCat<>$thisCat) { // true first time($lastCat not set), and each time a new category is found
//then write out a table heading with the category name
print '<th colspan="6" align="left">'; //heading spans all columns of table
print "<h3>".$row['category_name']."</h3>"; // print the next category heading
print "</th>\n";
}
print '<tr>';
print '<tr>'."\n";
print '<td>'.$row['topic_name'].'</td>'."\n";
print '<td class="description">'.$row['topic_desc'].'</td>'."\n";
print '<td><a href="'.$row['topic_url'].'" target="_blank">'.$row['topic_url'];
print'</a></td>';
print '</tr>'."\n";
// finally, we store the current category so next time the loop repeats,
// we can tell if the next item is in a new category or not
// if so, we write out a new heading - see if ($lastCat<>$thisCat) above
$lastCat = $row['category_name'];
}
print '</table>'."\n";
?> |
Partager