Hi,
I think a different database layout would be the first step to solve the problem:
tblClient (contains client info):
lngClientID (auto_increment, primary key)
strClientName (varchar(x) x=>maximum client name length, maybe a key over 10-15 characters if you want to order by name)
tblProject (contains project info):
lngProjectID (auto_increment, primary key)
strProjectTitle (varchar(x))
strInfo (varchar(x))
tblFile (contains file info):
lngFileID (auto_increment, primary key)
strFilename (varchar(x))
tblClient2Project (map clients to projects):
lngClientID ( no auto_increment, key)
lngProjectID (no auto_increment, key)
tblProject2File (map files to projects):
lngFileID (no aut_increment, key)
lngProjectID (no auto_increment, key)
This should reduce redundancies in your database.
This looks a bit complicated at the first look but might make things easier (there might be an easier solution, though 🙂)
You might be able to do stuff with just one query but I'd prefer a solution with several queries:
$result = mysql_query("SELECT * FROM tblClient ORDER BY strClientName");
while ($clientRow=@mysql_fetch_array($result)) {
$lngClientID = $clientRow["lngClientID"];
$strClientName = $clientRow["strClientName"];
echo "ID: ".$lngClientID." - Client: ".$strClientName."<br>\n";
$result2 = mysql_query("SELECT prj.* FROM tblClient2Project c2p, tblProject prj WHERE c2p.lngClientID='".$lngClientID."'");
while ($projectRow=@mysql_fetch_array($result2)) {
$strProjectTitle = $projectRow["strProjectTitle"];
$lngProjectID = $projectRow["lngProjectID"];
echo "- Project: ".$strProjectTitle."<br>\n";
$result3 = mysql_query("SELECT fil.* FROM tblProject2File p2f, tblFile fil WHERE p2f.lngProjectID=$lngProjectID");
while ($fileRow=@mysql_fetch_array($result3)) {
$strFilename = $fileRow["strFileName"];
echo "-- File: ".$strFilename."<br>\n";
}
}
}
You could do this with just one query but you would then have to do a lot more in PHP to find out when you would have to print which elements of the result.
I couldn't test the above code for any erros but something like that should work.
Thomas