Reply LinkBack Thread Tools Search this Thread
Old 09-05-2007, 15:41   #1 (permalink)
Repp55
Registered User
 
Repp55's Avatar
 
Join Date: Dec 2006
Location: Oklahoma City, Oklahoma -US-
Posts: 24
PHP - Show multi files under category w/o using select

I'm using php 5.2, mysql 5.0.22 and a Windows 2000 server.
My database is structured like so:

DB:
clfile ,
clfile_name
clfile_size
clfile_type
clfile_title
description
date_entered

cl_association,
cl_assoc_id
cl_file_id
cl_category_id
approved

categories
cl_category_id
cl_category


What I want to do is have all of the categories list out and each file list underneath them in a bullet list without having to use a form to select the categories. I have my code ready to where it will display one category and the files that are in that category but I'm not sure how to get all of them to do the same.

here is my code:

PHP Code:
<?php //view_files.php

$page_title 'View Files';


        
$first TRUE;
require_once (
'../_connect/intranet_connect.php');
$query ="Select cl_category_id FROM cl_categories";
$result mysql_query($query);
(list (
$type) = mysql_fetch_array($resultMYSQL_NUM));
{

$query "SELECT cl_category FROM cl_categories WHERE cl_category_id=$type";
        
        
$resultmysql_query($query);
        list (
$category) = mysql_fetch_array($resultMYSQL_NUM)OR die(mysql_error());
        
        
$first=TRUE;
        
$query "SELECT c.clfile_id, clfile_name, clfile_title, DATE_FORMAT(date_submitted, '%M %e, %Y') as d , description FROM clfile AS c, cl_association AS ca WHERE c.clfile_id = ca.clfile_id AND ca.cl_category_id=$type AND ca.approved = 'Y' ORDER BY date_submitted DESC";
        
        
$result mysql_query ($query);

        while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
        {
            
                if(
$first)
                {
                echo 
"<table border=\"0\" width=\"80%\" cellspacing=\"3\" cellpadding=\"3\" align=\"center\">
                        <tr>
                            <td><strong>$category</strong></td>
                            <Td><strong>Date</strong></td>
                        </tr>"
;
                        
$first FALSE;
                }
            
                echo 
"<tr><ul>
                        <td align=\"left\"><li><a href=\"../php/test/download.php?uid={$row['clfile_id']}\">{$row['clfile_title']}</a></td>
                        <td><font color=\"red\">*{$row['d']}*</li></td></a>
                    </tr>\n"
;
        }
    
            if(
$first)
                {
                    echo
'<p>There are no files</p>';
                }
            else
                {
                    echo 
'</table>';
                }
}
mysql_close();    

?>

Sorry about the long post. Thank you all for your help!
  Reply With Quote
Old 09-05-2007, 17:22   #2 (permalink)
Naatan
Web Developer
 
Naatan's Avatar
 
Join Date: Jan 2007
Location: Brussels
Posts: 214
Send a message via MSN to Naatan
So you basically want to do what you just showed us only for all the categories in there?

Im not sure if Im getting you right cus if I am I dont see what the problem is.. just make the category query a while or foreach loop aswell..
  Reply With Quote
Old 09-05-2007, 17:35   #3 (permalink)
Repp55
Registered User
 
Repp55's Avatar
 
Join Date: Dec 2006
Location: Oklahoma City, Oklahoma -US-
Posts: 24
I'm pretty sure you are understanding my problem correctly,
I changed

PHP Code:
(list ($type) = mysql_fetch_array($resultMYSQL_NUM)); 



to

PHP Code:
while(list ($type) = mysql_fetch_array($resultMYSQL_NUM))


as a suggestion from someone else and it still returns as the one category. I'm pretty much a noob at PHP so is there something I'm leaving out?
Thanks for the help

Last edited by Repp55 : 09-05-2007 at 17:54.
  Reply With Quote
Old 10-05-2007, 05:54   #4 (permalink)
Naatan
Web Developer
 
Naatan's Avatar
 
Join Date: Jan 2007
Location: Brussels
Posts: 214
Send a message via MSN to Naatan
I've never used list() in such a manner, so I don't know for sure if it would work, but I have my doubts, try the following:

PHP Code:
$query ="Select cl_category_id FROM cl_categories";
$result mysql_query($query);
while (
$cat mysql_fetch_array($resultMYSQL_NUM)) {
  echo 
$cat['cl_category_id'];


and see if that works for you.

note that instead of $type you use $cat['cl_category_id'] - I would recommend always doing mysql queries like this as if you were to change something in your database you wouldn't have to adjust all of your php code

Also try debugging, start with a single while loop for the categories and see if it prints out all the rows, then insert the other while loop inside and see if they work together nicely.
  Reply With Quote
Old 14-05-2007, 14:50   #5 (permalink)
Repp55
Registered User
 
Repp55's Avatar
 
Join Date: Dec 2006
Location: Oklahoma City, Oklahoma -US-
Posts: 24
Thanks for the help man I got it to work with your post and another one a little down the list.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8