cazconv Posted April 26, 2010 Share Posted April 26, 2010 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 More sharing options...
andrewgauger Posted April 26, 2010 Share Posted April 26, 2010 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/ Link to comment https://forums.phpfreaks.com/topic/199785-problem-with-html-table-with-php-data/#findComment-1048686 Share on other sites More sharing options...
cazconv Posted April 26, 2010 Author Share Posted April 26, 2010 thanks andrew, That worked great and it validates Link to comment https://forums.phpfreaks.com/topic/199785-problem-with-html-table-with-php-data/#findComment-1048696 Share on other sites More sharing options...
andrewgauger Posted April 26, 2010 Share Posted April 26, 2010 Cool. Suggestion: mark solved. Link to comment https://forums.phpfreaks.com/topic/199785-problem-with-html-table-with-php-data/#findComment-1048740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.