473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

printing ordered by query results as a header and table

First of all, I'm new to this level of PHP, so my apologies!

My goal is to create an HTML table that lists the title, type, size, and date of a document sorted by the project to which the document belongs. Like this:



I can get the data out of MYSQL with

Expand|Select|Wrap|Line Numbers
  1. $q = 'SELECT DISTINCT project_name, document_name, document_type, 
  2.  
  3. document_size, date_last_modified FROM documents LEFT JOIN projects ON 
  4.  
  5. documents.project_id = projects.project_id ORDER BY project_name ASC, 
  6.  
  7. date_last_modified DESC';        
I can create the table with project as a column with

Expand|Select|Wrap|Line Numbers
  1. if ($r) // ran OK,
  2. echo '<table summary="A listing of the project documents"> // Table header.
  3. <thead>
  4.           <tr>   
  5.            <th>Title</th>
  6.           <th>Type</th>
  7.           <th>Size (KB)</th>
  8.           <th>Date Last Modified</th>
  9.           </tr>
  10. </thead>';
  11.  
  12. // Fetch and print all the records
  13. $bg = '#dodcbc'; //set the bg color darker green
  14. while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
  15. $bg = ($bg=='#dodcbc' ? '#eff3e9' : '#dodcbc'); //switch the bg color
  16. echo '<tr bgcolor="' .$bg . '">
  17.           <td><a href="http://www.p.com/' . $row['filename'] .'"> ' . $row['document_name'] . ' </a></td>
  18.           <td>' . $row['document_type'] . '</td>
  19.           <td>' . $row['document_size'] . '</td>
  20.           <td>' . $row['date_last_modified'] . '</td>
  21.           </tr>';
  22.           }
  23. echo '</table>'; // Close the table.
  24. mysql_free_result ($r); // Free up the resources. 
But I'm stumped as to where to go from here. Basically I want to print the project_name as a <h2> before the table with the relevant documents listed in the table.

I know it must be so simple and basic, but I am completely missing it and have spent hours looking for a solution on the web. What am I missing???

Many thanks for your help--I truly appreciate it!
Mar 4 '10 #1
1 1611
zorgi
431 Expert 256MB
I see only 2 ways around it.
  1. You have to query your database for project_name before any of the code you show here.
  2. You have to use some sort of condition within your while loop to echo this header only once.
Second solution also means you would have to move around your code quite a bit.

In general its good to avoid conditionals if possible so I would probably opt for No1
Mar 4 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever...
7
by: JohnA | last post by:
Dear all, I'm trying to compose a query, but I don't know how to express the statement. I have 4 tables: Customers, Orders, Order Details and Products. Each customer has many orders and each...
4
by: Sami | last post by:
I hope someone will tell me how to do this without having to do any VB as I know nothing in that area. I am a rank beginner in using Access. I have created a database consisting of student...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
1
by: JackM | last post by:
I'm not sure if this qualifies as a mysql or a php question so I'm asking in both groups. I am pulling the results of a mysql query from my database and want to print the results into a two...
6
by: Ron | last post by:
Hi, I know Access allows for easy construction of a report setup to print labels from a table/query, etc. I've done that one. It works pretty well for what I need. However, is there an...
1
by: Casey Skousen | last post by:
I want to be able to batch print all records in a header table that have not yet been printed. This should be simple, but due to the format of the report, I cannot just print all records (the...
8
siridyal
by: siridyal | last post by:
I have a wholesale website that i'm working on that shows hundreds of items that are updated from time to time. These items are kept in a mysql database with several tables. I want to let the...
7
by: alf8kitty | last post by:
Hello, Im still very new to php and am having a problem. I return a MySQL query to a form in my php page and I want to be able to export the form data to Excel when the users clicks a link (or a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.