Jump to content


Photo

Nesting Problem?


  • Please log in to reply
3 replies to this topic

#1 sr1200

sr1200
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 22 June 2006 - 08:02 PM

Ive been pulling out hairs trying to get a piece of code to work.

I have a document repository that users upload files to. The files are uploaded to the appropriate folder and a record is added into the database that indexes when where by whom it was put as well as a flag for "public or private"

I got the upload portion of my program working great, now its time to display the documents that people have uploaded.
EX of database:

ID | name | file_name | file_flag | dept |
1 Bob info.txt 1 IT
2 Steve hex.doc 0 Exec
3 Sarah help.txt 0 IT
4 Tom help.txt 1 Acct


What i need to do is be able to display the data grouped by department,
so ex:
IT
info.txt
help.txt
Exec
hex.doc
Acct
help.txt

I created an sql query that counts the number of documents in each dept and returns only one value of each dept. ex:

IT - 2
Exec - 1
Acct - 1

So now i have a While statement that prints out each dept in teh database once.. (GREAT!)
however, i then cannot for some reason create another While statement WITHIN the first WHILE statement to matchup the files with the dept. heading.

I readup on some things regarding foreach, but couldnt get anything to work properly. If anyone has any example code snips that can point me in the right direction would be much appreciated.

#2 Eric_Ryk

Eric_Ryk
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 22 June 2006 - 08:25 PM

[!--quoteo(post=386948:date=Jun 22 2006, 04:02 PM:name=sr1200)--][div class=\'quotetop\']QUOTE(sr1200 @ Jun 22 2006, 04:02 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Ive been pulling out hairs trying to get a piece of code to work.

I have a document repository that users upload files to. The files are uploaded to the appropriate folder and a record is added into the database that indexes when where by whom it was put as well as a flag for "public or private"

I got the upload portion of my program working great, now its time to display the documents that people have uploaded.
EX of database:

ID | name | file_name | file_flag | dept |
1 Bob info.txt 1 IT
2 Steve hex.doc 0 Exec
3 Sarah help.txt 0 IT
4 Tom help.txt 1 Acct
What i need to do is be able to display the data grouped by department,
so ex:
IT
info.txt
help.txt
Exec
hex.doc
Acct
help.txt

I created an sql query that counts the number of documents in each dept and returns only one value of each dept. ex:

IT - 2
Exec - 1
Acct - 1

So now i have a While statement that prints out each dept in teh database once.. (GREAT!)
however, i then cannot for some reason create another While statement WITHIN the first WHILE statement to matchup the files with the dept. heading.

I readup on some things regarding foreach, but couldnt get anything to work properly. If anyone has any example code snips that can point me in the right direction would be much appreciated.
[/quote]
I'm going to assume that you are using MySQL, however if not you can work this around to your needs
$docs = mysql_query(..." ORDER BY dept");
$cur_dept = "";
while($row = mysql_fetch_assoc($docs))
{
   if($cur_dept != $row['dept'])
   {
      print $row['dept'] . "<br />";
      $cur_dept = $row['dept'];
   }
   print $row['file_name'] . "<br />";
}


#3 sr1200

sr1200
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 June 2006 - 05:55 PM

[!--quoteo(post=386966:date=Jun 22 2006, 04:25 PM:name=Eric_Ryk)--][div class=\'quotetop\']QUOTE(Eric_Ryk @ Jun 22 2006, 04:25 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I'm going to assume that you are using MySQL, however if not you can work this around to your needs
$docs = mysql_query(..." ORDER BY dept");
$cur_dept = "";
while($row = mysql_fetch_assoc($docs))
{
   if($cur_dept != $row['dept'])
   {
      print $row['dept'] . "<br />";
      $cur_dept = $row['dept'];
   }
   print $row['file_name'] . "<br />";
}
[/quote]

YOU ARE THE MAN!!!!

Worked Perfectly, just gotta format a bit, but thats it spot on! Thanks so much! [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

#4 Eric_Ryk

Eric_Ryk
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 23 June 2006 - 08:25 PM

[!--quoteo(post=387258:date=Jun 23 2006, 01:55 PM:name=sr1200)--][div class=\'quotetop\']QUOTE(sr1200 @ Jun 23 2006, 01:55 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
YOU ARE THE MAN!!!!

Worked Perfectly, just gotta format a bit, but thats it spot on! Thanks so much! [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
[/quote]
No problem man.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users