Hi all, I'm still new to PHP, so be gentle.... I'm trying to do this: I've got a site, where I'm showing a list of authors. The author names are hyperlinks. When a name is clicked, I'd like the author's titles to appear below his/her name, but the list of authors to continue on below it. Basically like an expanding/collapsing menu.
However, for some reason, the code I've got is not working right. The page loads, and shows the list of authors (so far so good). When an author's name is clicked, however, the title's appear above the list of authors, and several of the author's names drop off. But not always...(yeah, confusing...) I haven't been able to figure out what's driving whether they fall off or not.
Here's what I've got:
The page itself:
<?php require_once("includes/db_connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/header.php"); ?>
<?php
find_current_selection();
?>
<article>
<h1>Books</h1>
<div class = center>Select author by initial of last name.</div>
<p class = "center">
<?php echo author_navigation(); ?>
</p>
<ul class = "author">
<?php echo author_display($current_author); ?>
</article>
</section><!--end #mainContent-->
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="RightSidebar" -->
<aside>
<h1>No sidebar material yet</h1>
<p></p>
</aside>
<?php require_once("includes/footer.php"); ?>
Functions, as applicable to this:
function find_current_selection(){
global $current_initial;
global $current_author;
if(isset($_GET["initial"])){
$current_initial = $_GET["initial"];
$current_author = null;
} elseif(isset($_GET["author"])){
$current_initial = " ";
$current_author = $_GET["author"];
} else {
$current_initial = " ";
$current_author = null;
}
}
function author_display($author_array){
//$output = "<ul class=\"author\">";
$author_set = find_author_list();
while($author = mysqli_fetch_assoc($author_set)){
$output .= "<li";
if($author_array && $author["author_id"] == $author_array["id"]){
$output .= " class=\"SelectedAuthor\"";
} //END OF if($subject_array && $subject["id"]==$subject_array["id"])
$output .= ">"; // CLOSE li tag
$output .= "<a href=\"books.php?author=";
$output .= urlencode($author["author_id"]);
$output .= "\">";
$output .= htmlentities($author["Last_Name"]. ", " . $author["First_Name"]);
$output .= "</a>";
//titles start here
if ($author_array["author_id"] == $author["author_id"]){
$title_set = find_titles_for_author($author["author_id"]);
$output = "<ul class=\"title_name\">";
while($title = mysqli_fetch_assoc($title_set)){
$output .= "<li>";
//$output .= "<a href=\"index.php?author=";
//$output .= urlencode($title["Title"]);
//$output .= "\">";
$output .= htmlentities($title["Title"]) ;
//$output .= "</a>
$output .= "</li>";
}// END OF while($page = mysqli_fetch_assoc($page_set))
$output .= "</ul>"; //END OF 'title_name' class
mysqli_free_result($title_set);
}// END OF if
//END OF titles
$output .= "</li>";// END OF author li
}// END OF while($author = mysqli_fetch_assoc($author_set))
mysqli_free_result($author_set);
$output .= "</ul>"; //END OF 'authors' class
return $output;
}
function find_titles_for_author($author_id){
//Perform title query
global $connection;
$query = "SELECT * ";
$query .= "FROM titles ";
$query .= "WHERE Author_ID = {$author_id} ";
$query .= "ORDER BY Series_ID ASC";
$title_set = mysqli_query($connection, $query);
//test if there was a query error
confirm_query($title_set);
return $title_set;
}
Would love it if someone can tell me what I've done wrong.