This question about Using an extension: Answered
I'm getting a weird behavior out of EXTRACT. The short of it is if I have a heading on my table, it always seems to grab the heading instead of the first matching value.
The long version is this: I've been looking for a way to grep rows from a table based on a query and found EXTRACT as a way to do it. I don't know whether there are any other ways that work.
I have a table of people, where the first column is their name, the second is their building and the third is their room. That table is in a topic by itself.
I needed another topic that could, given a query string with the room number, give me the names of the people in that room. I am using it with an image map of the office floor plan.
As an aside, I tried using SEARCH as a starting point, but I couldn't figure out how to do a lookup.
<pre>%SEARCH{"%ROOM%" topic="PeopleTable" format=" * $Name" multiple="on" }%</pre>
This syntax doesn't work, but I do get the right number of rows; I just don't know how to query for the column value.
What does mostly work is
<pre>%EXTRACT{topic="PeopleTable" expand="off"
pattern="\|\s*(.*?)\s*\|\s*(.*?)\s*\|\s*(%ROOM%)\s*\|"
format=" * $1$n"}%</pre>
If I have no heading, it works perfectly.
The Table:
Name |
Building |
Room |
Blow, Joe |
ABA |
3103 |
Blow, Moe |
ABA |
3103 |
Flow, Joe |
ABA |
3113 |
Blow, Zoe |
ABA |
3113 |
With my search with room=3103, I got
If I use skip=1, i just get
If I get rid of the table heading, I get
--
MatthewKoundakjian - 27 Oct 2010
OH NO, I'm wrong. I am
always getting the first row in my results.
With my search the table without a heading with room=3103, I get
With my search the table without a heading with room=3113, I get
--
MatthewKoundakjian - 27 Oct 2010
I found something that works, though I can't figure out why the previous does not. The regex seems to behave just fine.
<!--
Interactive lookup
* Set ROOM = %URLPARAM{"room" default="3103"}%
-->
%EXTRACT{topic="%TOPIC%" expand="off"
pattern="^\s*\|([^\|]+)\|([^\|]+)\|\s*(%ROOM%)\s*\|"
format=" * $1$n"
}%
Test cases:
The result:
I'm considering this one answered.
--
MatthewKoundakjian - 05 Nov 2010