Just enquiring about the best way to do this. I've already got a working model (will explain it later on), but it occurred to me whilst i was doing it that its going to create a lot of recursive code which isn’t efficient. Any way here’s how the current system works.
At the top of my page i have links with the names of each alphabetical letter, at the end I have a link called "View All". These links display all appropriate glossary entries for the name of the link. For example the View All link will display all the entries in the glossary while the "A" link will only display those starting with the letter A.
In the following example i have used the "View All" link since this is what i have working. The HREF for this link is:Now, further on down the page i have the following code which will display all of the glossary enties in the database :PHP Code:' . $_SERVER['PHP_SELF'] . '?viewAll=Yes
Note the viewAll in the "View All" Link and the viewAll in the GET variable
The GET Variable at the top of the code checks if the "View All" Link has been activated (clicked) , If it has it runs the code below it and displays all the glossary entries on the page.PHP Code:<?php if(isset($_GET['viewAll'])) :
//gloss_id = ID of the entry
//gloss_acro = Acronym or Word to be entered e.g CPU
//gloss_def = Defination of Acronym e.g Central Processing Unit
//gloss_info = Information about this item e.g heart of a computer
//gloss_char = Character Symbol for link sorting. Not needed for View All Link
//gloss_date = Date of entry
$datalist = @mysql_query("SELECT gloss_id, gloss_acro, gloss_def, gloss_info, gloss_char, gloss_date
FROM glossary
ORDER BY gloss_acro ASC");
if (!$datalist) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($data = mysql_fetch_array($datalist)) {
$g_id = $data['gloss_id'];
$g_acro = $data['gloss_acro'];
$g_def = $data['gloss_def'];
$g_info = $data['gloss_info'];
$g_date = date("jS-M-y" ,$data['gloss_date']); // Not working yet
// Display the glossary entries
echo "$g_acro <br /> $g_def <br />$g_info<br /> $g_date<br /><br />" ;
}
endif;?>
This is when I suddenly realized i would need a mass of code to display the Glossary entries via their Alphabetical links. What i mean is if i wanted to display all Glossary entries starting with "A" I would need to change the "A" link HREF toand the $GET variable attribute to check "A" then run the code blow it with the appropriate changes to display all entries starting with A made. I would need a total of 27 blocks of similar code glossary to work as ive described above. As you can see this would make a very large list of code which basically does the same thing.PHP Code:' . $_SERVER['PHP_SELF'] . '?A=Yes
Im guessing there’s a much better way to do this and a much shorter way to do it. If so could anyone guide me in the right direction please? If there’s something you don't understand in my explanation let me know so i can clarify things a bit.![]()


LinkBack URL
About LinkBacks
Reply With Quote