Current location: Hot Scripts Forums » Programming Languages » PHP » displaying multiple files per topic


displaying multiple files per topic

Reply
  #1 (permalink)  
Old 04-24-07, 10:32 AM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
displaying multiple files per topic

Does any one have an idea on generate the following with a select stmt?
EXAMPLE:
HTML Code:
Title
doc 
doc
doc
 
Title
doc
 
Title
doc
doc 
doc
Basically what is shown above is there will be one DISTINCT title and then under it any files associated with that title.

This is what I am doing currently, but it is only displaying 1 file per title.
PHP Code:

<?php

      
      $query 
"SELECT * FROM $tbl_name WHERE titlehide='no' GROUP BY title";
      
$result mysql_query($query) or die("Invalid query: $query");
      if(
mysql_num_rows($result) == 0)
      echo 
"No locations exist";
      
      else
      {
       while(
$row mysql_fetch_array($result))
       {
       
$path 'http://192.168.0.104/usa/docs/OperationManuals';
       
$folder $row['url'];
       
$doc $row['document'];
        echo 
"<p><b>".$row['title']."</b><br>";
        echo 
"<a href='$path/$folder/$doc'>".$row['document']."</a></p>";
       }
      }
     
?>
__________________
learning like everyone else
Reply With Quote
  #2 (permalink)  
Old 04-24-07, 11:46 AM
tomasgtz tomasgtz is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
query

the problem is the query, you are making a group, so only will bring one row by title.

try to bring all rows and group it, in php... something like this

PHP Code:

$query "SELECT * FROM $tbl_name WHERE titlehide='no' ORDER BY title";
$result mysql_query($query) or die("Invalid query: $query");
if(
mysql_num_rows($result) == 0)
{
      echo 
"No locations exist";
}
else
{
   while(
$row mysql_fetch_array($result))
   {
       
$docs[$row["title"]][] = array('url' => $row['url'], 'doc' => $row["document"]);
   }
}


foreach(
$docs as $title => $tmp)
{
   echo 
$title."<br>";
   
   foreach(
$tmp as $key => $data)
   {
       
// etc etc ......
   
}

__________________
Best regards,
See the best CMS http://www.publicante.com

Tomas Gutierrez

Last edited by Nico; 04-24-07 at 12:07 PM.
Reply With Quote
  #3 (permalink)  
Old 04-24-07, 11:59 AM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
alright, makes sence. thanks tomasgtz
__________________
learning like everyone else
Reply With Quote
  #4 (permalink)  
Old 04-24-07, 01:28 PM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Tomasgtz,
I am experiancing the following:

instead of printing the name of the file it is generating a number
title
0
title
0
1
2
3
title
0
2
...

any thoughts of why this is happening?
PHP Code:

<?php
//Select title from a drop down, and allow title deletion (The titlehide flag is set to 1)
//select the titles that are different
$query "SELECT * FROM $tbl_name WHERE titlehide='no' ORDER BY title";
$result mysql_query($query) or die("Invalid query: $query");
if(
mysql_num_rows($result) == 0)
{
echo 
"No locations exist";
}
else
{
while(
$row mysql_fetch_array($result))
{
$available_titles[$row["title"]][] = array('url' => $row['url'], 'doc' => $row["document"]);
$path 'http://foo/foo2/bar/bar2';
$folder $row['url'];
$doc $row['document'];
}
}
foreach(
$available_titles as $title => $tmp)
{
echo 
$title."<br>";
foreach(
$tmp as $doc => $data)
{
print_r("<a href='$path/$folder/$doc'>".$doc."</a></br>");
}
}
?>
__________________
learning like everyone else
Reply With Quote
  #5 (permalink)  
Old 04-24-07, 01:38 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:

print_r("<a href='$path/$folder/$doc'>".$doc."</a></br>"); 

Try $data instead of $doc.
Reply With Quote
  #6 (permalink)  
Old 04-24-07, 01:46 PM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
Close, now instead of displaying the file name is displaying
title
Array
title
Array
title
Array
Array
Array
Array
Array
__________________
learning like everyone else
Reply With Quote
  #7 (permalink)  
Old 04-24-07, 04:25 PM
pkcidstudio's Avatar
pkcidstudio pkcidstudio is offline
Coding Addict
 
Join Date: Nov 2005
Posts: 332
Thanks: 0
Thanked 0 Times in 0 Posts
-SOLVED-
in case any one has been currous on how this one was going to end. here is the completed source.
PHP Code:

      <?php
      
//Select title from a drop down, and allow title deletion (The titlehide flag is set to 1)
      //select the titles that are different
      
$query "SELECT * FROM $tbl_name WHERE titlehide='no' ORDER BY title";
      
$result mysql_query($query) or die("Invalid query: $query");
      while(
$row mysql_fetch_array($result))
      {      
       
$path 'http://foo/foo2/bar/bar2';
       
$available_titles[$row["title"]][] = array('url' => $row['url'], 'doc' => $row["document"]);            
}
      foreach(
$available_titles as $title => $tmp)
      {
       echo 
$title."<br>";
       foreach(
$tmp as $doc => $data)
      {       
       
//this is grabbing the information from the array $available_titles to fill these fields.
       // $data + the row = dynamic!
       
echo("<a href=\"".$path."/".$data['url']."/".$data['doc']."\">".$data['doc']."</a></br>");
      } 
       echo 
"<br>";
      }
     
?>
__________________
learning like everyone else
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DIsplaying directory files alphabatically itssami PHP 1 05-13-06 02:50 PM
displaying latest added files in subdirectory itssami PHP 1 05-02-06 03:20 PM
Download multiple files Bas Steijvers JavaScript 1 06-15-05 02:24 PM
Multiple Resource Files? tim8w Visual Basic 1 03-25-05 07:10 PM
multiple Text files to html. andreas66 JavaScript 4 06-13-03 08:04 AM


All times are GMT -5. The time now is 06:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.