Quote:
quote:Originally posted by major dynamic123
Your explanation is almost to what I wanted to do. Actually I have a page called books.php. I plan to use only books.php to do the work. My initial plan is to:
1. create a list of alphabetical letters(a to z) using html code. I've done this already using A | B | ...Z
|
I'd stay away from using the tag as it's been deprecated. If you're going to use a stylesheet, use either the <div> or <span> tags around your text and set all your font properties within you CSS class.
Quote:
quote:Originally posted by major dynamic123
2. when a user visits the books.php page, I want the user to click any of the letters available in books.php, A till Z. The letters, A till Z represents the book categories; ie:A for Animals, Z for Zoology. Then the user will be presented with all the book categories beginning with letter A.
|
Okay, so before a user can select a book, they have to select a letter for a category, which brings up a list of all the categories, then select the category they're interested in, which brings up a list of all the books in that category, then select the book(s) they were interested in?
If you don't have too many categories, it might be more user friendly to have a single page with ALL your categories listed alphabetically. Clicking on the anchor link will work just like a regular anchor and take you to the part of the page where that letter's categories start.
For example:
<a href="#A">A</a> | <a href="#B">B</a> ...
<a name="A">--A--</a>
Animals
Automobiles
<a name="B">--B--</a>
Bookkeeping
...
All of this code can be generated very easily with PHP. Your original list of anchors is simple:
// first we create an array containing all 26 letters.
$letters = array();
$begin = ord('A');
$end = ord('Z');
for ($i = $begin; $i <= $end; ++$i)
{
$letters[] = chr($i);
}
// now we use that array to create the list of anchor links:
$anchors = array();
foreach($letters as $letter)
{
$anchors[] = " <a href=\"#{$letter}\">--{$letter}--<a>\n";
}
$anchor_string = join(" | ", $anchors);
echo "<p>{$anchor_string}</p>\n";
// now output all the categories.
$query = "SELECT id, category FROM categories ORDER BY category ASC";
$result = mysql_query($query);
if($result)
{
$categories = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$categories[] = $row;
}
$first_letter = '';
foreach($categories as $cat)
{
// check if we're starting a new letter
if($first_letter != $cat[0])
{
$first_letter = $cat[0];
echo "<a name=\"{$first_letter}\">--{$first_letter}--</a><br/>\n";
}
echo "{$cat}<br/>\n";
}
}
Keep in mind that I haven't tested this code -- I just wrote it from scratch here in this forum reply window. There's definitely other ways to do it, but it's a start.
Quote:
quote:Originally posted by major dynamic123
3. My initial plan is to allow PHP do the work in retrieving book titles in the Animals book category(assuming that the user selects A and then selects Animals).
I already have the idea on how to do this, but I need a complete php code to guide me and even give me an idea how it should be written.
Currently, my database(MySQL) has a table called "categories". The attributes are
1. category_id(primary key) and
2. category(for various book categories).
I hope this explanation will help clarify some of the doubts you have.
|
Well, where are your books stored? What's the schema there? Do books only belong to one category? What about a PHP book? Doesn't that belong in the Computers, Programming, and PHP categories?
Your question boils down to: "How can I select the books that belong to a single category?", but you haven't told me how you store the books in your database, which is vital to know before answering the question.
Take care,
Nik
http://www.bigaction.org/