m00nz00mer Posted February 29, 2008 Share Posted February 29, 2008 hey there, i have an array that selects all booktitles and authors in a database however some books have more than one author... im trying to display them using this code... $result = mysql_query("SELECT bookISBN,bookYear, bookTitle FROM nbc_book"); while($row = mysql_fetch_array($result)) { $authArray = mysql_fetch_array($authNameResults); //Display the results with links to each category echo '<div class="categoryLinks"><div class="detailTextGrey">Book Title: </div><a href="bookinfo.php?bookID='.$row['bookISBN'].'">'.$row['bookTitle'].'</a><br /><div class="detailTextGrey">Author(s): </div><div class="detailText"><div class="detailText">'; while($row2 = mysql_fetch_array($authArray)) { echo($row2['authorName']); } echo ' ('.$row['bookYear'].') </div></div><br/><br/>'; } ?> however im getting this error... mysql_fetch_array(): supplied argument is not a valid MySQL result resource does anyone know whats wrong with this...? Ty Quote Link to comment Share on other sites More sharing options...
Baabu Posted February 29, 2008 Share Posted February 29, 2008 $authArray = mysql_fetch_array($authNameResults); this error is because you are providing the variable which is not been set or it does not have any identifier to get the results from which array?? Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 29, 2008 Share Posted February 29, 2008 where are you getting $authNameResults from? it is always a good idea when developing to use an "or die()" statement on every mysql_query() call. like so: $query = "SELECT bookISBN,bookYear, bookTitle FROM nbc_book"; $result = mysql_query($query) or die("Query: ".$query."<br>".mysql_error()); cheers, Quote Link to comment Share on other sites More sharing options...
m00nz00mer Posted February 29, 2008 Author Share Posted February 29, 2008 sorry this is the full code... <?php $authName = "SELECT nbc_author.authorName FROM nbc_author INNER JOIN nbc_authbook ON nbc_author.authorID = nbc_authbook.authorID"; $authNameResults = mysql_query($authName); //Retriving all of the books $result = mysql_query("SELECT bookISBN,bookYear, bookTitle FROM nbc_book"); while($row = mysql_fetch_array($result)) { $authArray = mysql_fetch_array($authNameResults); //Display the results with links to each category echo '<div class="categoryLinks"><div class="detailTextGrey">Book Title: </div><a href="bookinfo.php?bookID='.$row['bookISBN'].'">'.$row['bookTitle'].'</a><br /><div class="detailTextGrey">Author(s): </div><div class="detailText">'.$authArray['authorName'].' ('.$row['bookYear'].') </div></div><br/><br/>'; } ?> Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 29, 2008 Share Posted February 29, 2008 please note what i said and tell us if php says anything... also try this: $result = mysql_query("SELECT bookISBN,bookYear, bookTitle FROM nbc_book"); while($row = mysql_fetch_array($result)) { //Display the results with links to each category echo '<div class="categoryLinks"><div class="detailTextGrey">Book Title: </div><a href="bookinfo.php?bookID='.$row['bookISBN'].'">'.$row['bookTitle'].'[/url] <div class="detailTextGrey">Author(s): </div><div class="detailText"><div class="detailText">'; while($row2 = mysql_fetch_array($authNameResults)) { echo($row2['authorName']); } echo ' ('.$row['bookYear'].') </div></div> '; } Quote Link to comment Share on other sites More sharing options...
m00nz00mer Posted February 29, 2008 Author Share Posted February 29, 2008 afraid that doesnt work...it displays a list of all the authors in the bd under one booktitle. Quote Link to comment Share on other sites More sharing options...
uniflare Posted February 29, 2008 Share Posted February 29, 2008 ok sry im in a rush, basiclly you need to first query the books, then inside the loop, query the authors for that book. i would give code example but in a rush sry. sorry my sql is really bad but an easier way would be to store all the books of a specific author in an author table, then store books in a seperate table with an author field. then you would "Select * From `author_table` WHERE `authorname`='$book_author';" inside your book loop hope this helps and good luck Quote Link to comment Share on other sites More sharing options...
m00nz00mer Posted March 1, 2008 Author Share Posted March 1, 2008 any code examples? ty for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.