I have a while loop fetching a row and I'm trying to create a structure so that each row will create 2 links. The first is a German word and the second being an English one. The output I'm getting is repeated as if the row isn't being incremented. I've narrowed it down to this:
PHP:
while ($row = $database->row()->fetch()) {
foreach ($row as $value) {
$this->data .= $value . "!";
}
list($this->pid, $this->german, $this->english) = explode("!", $this->data);
$this->links .= "<a href=\"#\" class=\"german $this->pid\">$this->german</a><br/><a href=\"#\" class=\"english $this->pid\">$this->english</a><br/>";
}
Output:
die Männer
men
die Männer
men
$row = array();
while ($row = $database->row()->fetch()) {
$row[] = $row;
}
foreach ($row as $value)
{
$this->data .= $value . "!";
list($this->pid, $this->german, $this->english) = explode("!", $this->data);
$this->links .= "<a href=\"#\" class=\"german $this->pid\">$this->german</a><br/><a href=\"#\" class=\"english $this->pid\">$this->english</a><br/>";
}
I've solved the problem by looking at the keys and creating variables based on a simple matched string test. If anyone can improve my answer I would like to hear it. Thanks.
PHP:
while ($row = $database->row()->fetch()) {
while(list($key, $value) = each($row)) {
if ($key == "PID") {
$this->pid = $value;
}
if ($key == "german") {
$this->german = $value;
}
if ($key == "english") {
$this->english = $value;
}
}
$this->links .= "<a href=\"#\" class=\"german $this->pid\">$this->german</a><br/><a href=\"#\" class=\"english $this->pid\">$this->english</a><br/>";
}