Recursive Display of information
| From: | Peter Beckman | Date: | Mon, 19 May 2003 21:23:33 +0000 |
| Subject: | Recursive Display of information | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-27899@lists.php.net to get a copy of this message | ||
I'm trying to write a function that is reusable. The goal of this function
is to drill down into different tables based on different keys.
Let's say there are 3 tables, all one to many relationships.
Table A 1 --> many Table B 1 --> many Table C
I'm trying to do something like this:
function recurse($x) {
$r = db_query("select * from {$x['table']} where
{$x['col']}='".addslashes($x['val'])."'");
echo "<table>";
while($row = mysql_fetch_array($r)) {
echo "<tr>";
while(list($k,$v)=each($row)) {
if ($k == $x['match']) {
$url = preg_replace("/%%$k%%/",$v, $x['url']);
$url = preg_replace("/%%table%%/",$x['nexttbl'],
$x['url']);
printf("<td><a
href='%s'>%s</a></td>",$url, $v);
} else {
echo "<td>".$v."</td>";
}
}
echo "<tr>";
}
echo "</table>";
}
The idea being that I pass it the table to grab, the restriction on it (col
and val), and pass it a column to make clickable to the next table in the
line. My problem is getting it started, and following it through, passing
the right info.
Does anyone have a solution for this type of thing already?
Peter
---------------------------------------------------------------------------
Peter Beckman Internet Guy
beckman@purplecow.com http://www.purplecow.com/
---------------------------------------------------------------------------