All,
I'm trying to build a script that will re-iterate through a list of
subjects and display the first letter of the subject name and then a list
of all the subjects that start with that letter.
I tried doing this a few years ago and someone (Joseph?? rudy??) helped me
then, but I can't find the post in the archives. I am after the following:
==========================
Sub-Categories for "Television":
D
- Drama
- Documentary
S
- Soaps
- Sit-Com
=========================
I have the following code currently, but please feel free to re-write if
needed!
========================
// see if there are any further child categories
$grabChildSubjects = "SELECT * FROM subjectAreas WHERE subjectParentId =
$sid AND subjectStatusId = 1 ORDER BY subjectName";
$child = mysql_query($grabChildSubjects);
// count the number of rows returned. If there aren't any, offer to start
a new post and list the current ones
$numChildren = mysql_num_rows($child);
if($numChildren > 0)
{
// set the page title
$titleSql = "SELECT subjectName,subjectId FROM subjectAreas WHERE subjectId
= $sid AND subjectStatusId = 1";
$titleArray = $d->getResultsArray($titleSql);
$title = $titleArray['subjectName'];
$content = $content."<p>$numChildren sub-categories
found...</p>\n\t<p>\n\t";
// create the top listing
$rowOfLetters = "<p>Browse by letter<br />";
// display the children
// check records actually exist!
//Set letter to null so that var exists but will still be displayed
$letter = "";
// Iterate through records
for($i=0; $i < $numChildren; $i++)
{
$row = mysql_fetch_array($child);
// get first letter of subject name
if(substr($row["subjectName"], 0, 1) != $letter){
$letter = substr($row["subjectName"], 0, 1);
//print it with line breaks before and after for nice formatting ;o)
$content=$content."<p><a
name=\"$letter\">$letter</a>\n\t\t<ul>\n\t\t\t";
$rowOfLetters = $rowOfLetters." <a href=\"#$letter\">$letter</a>";
// Write the link to the posts for this subject
$content=$content."<li><a
href=\"browse.php?sid=".$row['subjectId']."\">".$row['subjectName']."</a></li>\n\t\t";
}
$content = $content."\n\t</ul></p>\n";
}
$content=$rowOfLetters."</p><p><a
href=\"addSubject.php?par=$sid\">Add a Sub-Category
here</a></p>".$content;
====================================================
Thanks in advance for any help,
Cheers,
Matt
--
Matthew Macdonald-Wallace
[EMAIL PROTECTED]
"Sed quis custodiet ipsos custodies?"
____ The WDVL Discussion List from WDVL.COM ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or
use the web interface http://e-newsletters.internet.com/discussionlists.html/
Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk
________________ http://www.wdvl.com _______________________
You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016
Please include the email address which you have been contacted with.