I'm confused about how to use "datatool" to read variables from a row in my database, and pass them on to be formatted in my text. I don't want to make a table, but that's about all there seems to be examples of on the Internet.
I have a CSV file made up something like this:
name|points
John|172
Sue|120
Mike|64
After two days of staring at the datatool manual, this is the extent of my success:
\documentclass{memoir}
\usepackage{datatool}
\DTLsetseparator{|}
\begin{document}
\DTLloaddb{players}{database.csv}
\DTLforeach*{players}{\name=name,\points=points}
\subsection{\name}
\textit{\points}
\end{document}
That prints the chosen variables with the formatting I desire, but it only does so with the last entry in the database. My guess is that "\dtlgetrowforvalue{players}{1}{John}" could be used to find John's row in the database, but I don't understand how to integrate that with the commands that read and display the variables.
I am unfamiliar with much of the terminology used in the manual, and finding no examples that look like what I wish to achieve, my attempts at bullying my way through by trial and error have failed. I don't necessarily need a working example, but I would very much like for someone here to put me onto the appropriate commands, at least.
Best Answer
\DTLforeach
takes three compulsory arguments, not two as in your example. This fixes your example:This produces:
Edit:
\DTLforeach
is a repetitive (loop) command designed to perform a particular action for each row of data. If you just want to lookup information from a single row of the data, there are a number of methods to do this. Here are some examples:This produces: