This topic is locked

Creating An A-Z Quick Link Bar

1/23/2013 11:53:18 PM
PHPRunner General questions
W
wfcentral author

My client has a database with 100s of names in it. They asked me to create a row of letters at the top of the list page that has the letters A B C D E F... all the way to Z. So they can click on the letter A and get all names that start with A. Same for the other letters.
I managed to hand-code something that worked using search URLs... now that I have upgraded them to a new version of PHPRunner my hand-code got lost and I have to do it again.
Before I hand-code it I want to know if there is a simple solution that someone else has tried?

C
cgphp 1/24/2013
F
FunkDaddy 2/6/2013

I recently did this exact thing you are asking for.
Here are the steps I took:

  1. Inserted a custom PHP Snippet right after the footer in visual editor (of the list page) as follows



//Create the ABC control but keep it hidden on page load

//Use Jquery with JS OnLoad event to move this entire div into a td cell element on page

echo "<div id='abc_pag' style='display:none;text-align:center;;'>";

echo "<ul style='list-style-type:none;line-height:2em;font-size:medium;color:red'>";

foreach (range('A', 'Z') as $letter) {

echo "<li><a href='your_table_tbl_list.php?abc=".$letter."'>".$letter."</a></li>";

}

echo "</ul>";

echo "</div>";


2. Then here is the JQuery code to place the A - Z links (I chose to place them on the far right handside of the page (you'll notice in the code above it's laid out vertically.. meaning each letter is stacked on top of each other from A to Z)



//dynamically move the ABC pagination control inside the empty column given to us by phpr by default

$('#abc_pag').prependTo($('.runner-right'));

$('#abc_pag').css('display','inline');


3. No notice that in step 1 I added a query string URL parameter which I called "abc" (look at the href of the link). I use this $_GET['abc'] variable in the List Page: Before SQL query event to filter the results, like this:



//This parameter is created from the abc_pagination snippet and allows for rolodex search by selected first letter

if(isset($_GET['abc'])){

$strWhereClause = whereAdd($strWhereClause, " Last_Name LIKE '".$_GET['abc']."%'" );

}


That's it. Now when you click on a letter it reloads the list page, but with a URL parameter attached.. then before SQL interprets that value and filters your query accordingly by first letter matched.