Jump to content

Problem with html table with php data


cazconv

Recommended Posts

Hi, I have a php query thats getting all data into a table the problem is for one book there can be multiple authors, when this is displayed the data goes onto another row on the table  :'( also i need it to be html compliant which it isnt i think its because i have two while loops, well heres my code any help would be brilliant

 

echo '<table border="1" cellpadding="5" cellspacing="0">';
echo '<tr><th>Title</th><th>Year of publication</th><th>Author</th></tr>';
$sql = "Select Distinct (bookISBN), bookTitle, bookYear from nbc_book Group by bookTitle Asc";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
    $bookISBN = $row['bookISBN'];
echo "<tr><td><a href=\"bookdetails.php?bookISBN=" . $row['bookISBN'] . "\">";
echo htmlentities($row['bookTitle'])."</a></td>";
echo " ";
echo "<td>".$row['bookYear']."</td>";
    echo " ";
$query = "Select authorName from nbc_author a inner join nbc_authbook b on a.authorID = b.authorID where bookISBN = '$bookISBN'";
$result = mysql_query($query);
while ($rec = mysql_fetch_array($result))
{
$authorName = $rec['authorName'];
echo "<td>".$authorName." "."</td></tr>";
}
}

echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/199785-problem-with-html-table-with-php-data/
Share on other sites

replace:

while ($rec = mysql_fetch_array($result))

{

$authorName = $rec['authorName'];

echo "<td>".$authorName." "."</td></tr>";

}

 

with

while ($rec = mysql_fetch_array($result))
{
$authorName = $rec['authorName'];
echo "<td>".$authorName." "."</td>";
}
echo "</tr>";

 

Validating HTML is a bit of a process that is best served by using W3's service.  It takes a bit of know how, but you can't just look at a snapshot of a script and figure it out.  Also, the change I suggest does get you going in the right direction.  Look at the source code after the php compiles, look for tags that don't match, but most of all, use:

http://validator.w3.org/

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.