Skip to main content
Inspiring
October 14, 2012
Answered

Dynamic link from Alphabet character: Example/tutorial?

  • October 14, 2012
  • 1 reply
  • 1366 views

I am hoping someone can point me at a tutorial/example of what I am trying to do; that is create a dynamic link from one page, based on the alphabet. 

To try to explain

My database holds for example, a CD collection, listing artists , an ID and albums by them (Art_Name, Alb_Title, ArtID) .  From a page where I have the alphabet listed (A,B,C etc on a toolbar).  Im looking for a way of linking to a dynamic page, where all the artists beginning with a specific letter will be listed

My efforts up to date can either link a single artist, or all artists, but not the list of all artists with a common letter!

I know I could do this by creating a target page for each letter, then using filtering in the RS, but feel there should be a more elegant solution

Thanks

This topic has been closed for replies.
Correct answer David_Powers

The link goes in the repeat region that displays the initial letters.

<?php echo $_SERVER['PHP_SELF']; ?> simply inserts the filename of the current page.

It's followed by a query string. In my example, I used ?letter=<?php echo $row_letterQuery['letter']; ?>.

The resulting HTML output will be something like this:

<a href="this_page.php?letter=C">C</a>.

So, when the page loads, the second recordset will use $_GET['letter'] to find all artists with names that begin with C.

1 reply

David_Powers
Inspiring
October 14, 2012

Moved to the Developing server-side applications with Dreamweaver forum.

I don't know of a tutorial that shows how to do this, but the principle is quite simple.

You need two recordsets: one for the initial letters, the other to display the results.

The recordset for the initial letters needs to look for the letters of the alphabet that have artists listed. The SQL should be something like this:

SELECT DISTINCT LEFT(Art_Name, 1) AS letter

FROM table_name

ORDER BY letter ASC

This will get the letters of the alphabet that have artists names in the database. Make each letter a link that reloads the same page with the letter as a query string parameter. The code will look something like this (assuming the recordset is called letterQuery:

<a href="<?php echo $_SERVER['PHP_SELF']; ?>?letter=<?php echo $row_letterQuery['letter']; ?>"><?php echo $row_letterQuery['letter']; ?></a>

The second recordset simply looks for values matching the URL parameter "letter".

The SQL query would be like this:

SELECT * FROM table_name

WHERE Art_Name LIKE var1%

ORDER BY Art_Name

In the Variables field of the Advanced recordset dialog box, define var1 as Text, set the Default value as A (or whichever letter is first in your existing list of artists), and set the Runtime Value to $_GET['letter'].

Inspiring
October 14, 2012

HI David

Yes, I wondered if that might be a more applicable forum

Thanks for the help, I am not going to be able to look further at this for a few hours, so will try later.  Ive not used the LIKE command previously, but have some across it

Regards