473,796 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display sql query output in html table

Greetings:

As evident from a previous post, I am a php noob. I would like to
display MySQL query results in an html table with one of the row values as a
category and the rest of the data displayed under the relevant category.

I can get as far as displaying the data in a nice readable format but I
don't know how to have the records placed under their corresponding
category. This is my code thus far (sans the html output):

....ORDER BY cat ASC';
while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
printf("%s Class: %s Description: %s", $row["cat"]$row["title"],
$row["desc"]);
}

As you can see, this only outputs each record with the selected rows but
we show multiple instances of the same category. I know why this works the
way it does, I just don't know how to make it work the way I want. Advice
is appreciated. Thanks in advance.

Also, any good links for understanding and using arrays are welcome.
--

Regards,

Jerry M. Gartner
Jun 23 '06 #1
2 21059
Jerry M. Gartner wrote:
Greetings:

As evident from a previous post, I am a php noob. I would like to
display MySQL query results in an html table with one of the row values as a
category and the rest of the data displayed under the relevant category.

I can get as far as displaying the data in a nice readable format but I
don't know how to have the records placed under their corresponding
category. This is my code thus far (sans the html output):

...ORDER BY cat ASC';
while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
printf("%s Class: %s Description: %s", $row["cat"]$row["title"],
$row["desc"]);
}

As you can see, this only outputs each record with the selected rows but
we show multiple instances of the same category. I know why this works the
way it does, I just don't know how to make it work the way I want. Advice
is appreciated. Thanks in advance.

Also, any good links for understanding and using arrays are welcome.


Something like:

$cat = ""; // Or any value you would never have for a category
while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
if ($row['cat'] != $cat) {
echo $row['cat'] . ' ';
$cat = $row['cat'];
}
echo 'Class: ' . $row['title'] . "Descriptio n" . $row['desc'];
}

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jun 24 '06 #2
That did the trick thanks much for the input.

--

Regards,

Jerry M. Gartner

"Jerry Stuckle" <js*******@attg lobal.net> wrote in message
news:d4******** *************** *******@comcast .com...
Jerry M. Gartner wrote:
Greetings:

As evident from a previous post, I am a php noob. I would like to
display MySQL query results in an html table with one of the row values
as a category and the rest of the data displayed under the relevant
category.

I can get as far as displaying the data in a nice readable format but
I don't know how to have the records placed under their corresponding
category. This is my code thus far (sans the html output):

...ORDER BY cat ASC';
while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
printf("%s Class: %s Description: %s", $row["cat"]$row["title"],
$row["desc"]);
}

As you can see, this only outputs each record with the selected rows
but we show multiple instances of the same category. I know why this
works the way it does, I just don't know how to make it work the way I
want. Advice is appreciated. Thanks in advance.

Also, any good links for understanding and using arrays are welcome.


Something like:

$cat = ""; // Or any value you would never have for a category
while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
if ($row['cat'] != $cat) {
echo $row['cat'] . ' ';
$cat = $row['cat'];
}
echo 'Class: ' . $row['title'] . "Descriptio n" . $row['desc'];
}

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Jun 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10459
by: adam | last post by:
Hi, I have an issue that i just cant seem to figure out hope some one can help. right i am getting people to input the own images directly into a blob within a mysql database. then on the next page i want to display the image with in a nicely formatted html table so i can put the image where i choose on the page *this code is only putting the image on the top of the page and wont let me output any other text etc*
2
1970
by: erica | last post by:
Hi, I am currently writing PHP code for some polling software. When someone votes, it stores their IP address in the database. From then on, they cannot vote in that particular poll, they only view the results. There are several polls in the database, and there is a field called "status". When it is 0, the poll is "active" and can be voted upon. When it is 1, it is archived and one can only view the results. But, there seems to be...
1
6605
by: Charlie | last post by:
Hello, I have data in an Access table that I would like to export to multiple HTML tables. I would like to split the data in the Access table (about 92,000 records) into multiple HTML tables/files to reduce download time and bandwidth usage on my web server. That way, the user can select a particular page to download instead of downloading a page with all of the records. I would like to set a limit of only 500 records per file.
18
3210
by: Terry Holland | last post by:
I have an asp.net (1.1) application that connects to a SQL server 2000 db. I have a stored procedure in my db that out puts data in xml format. What I need to be able to do is display that xml that I retrieve from my stored proc and display it in a web page formatted as I want. I have managed to get my xml to display as I wish if I manually run my stored proc in QA and copy the xml into notepad and save it as Test.xml. I reference my xsl...
3
2182
by: Augustin Prasanna | last post by:
I need to display some 200 records (dynamic) on the screen.. I need to display records from 2 tables (one to many relationship) output would look like Customer Id Name Phone NO 1 abc 23949495 34945959
5
2761
by: PHPBABY3 | last post by:
Hi, 1. I have two SQL tables. I will call them employees and departments: EMP: LAST_NAME, FIRST_NAME, DEPTNM DEPT: NUM, NAME Input: text string FIND Output: the LAST_NAME, FIRST_NAME and department name NAME (link DEPTNM
4
2438
by: rn5a | last post by:
A MS-Access DB has 3 tables - Teacher, Class & TeacherClass. The Teacher table has 2 columns - TeacherID & TeacherName (TeacherID being the primary key). The Class table too has 2 columns - ClassID & ClassName (ClassID being the primary key) The TeacherClass table has 3 columns - TCID (AutoNumber), TeacherID & ClassID. One teacher can teach multiple classes & one class can be taught by multiple teachers. The TeacherClass table basically...
4
5917
by: beary | last post by:
Hi, I have 2 tables as follows: table1 (studid,studfirst,studlast) table2 (resid,studid,resnum,resgrade) In table 1 are 2 records: Record 1: '1','Michael','Jackson' Record 2: '2','John','Williams'
3
4834
by: DigitalWallfare | last post by:
Hi all, This is my first post here, but i've lurked for a while. I'm working on a website but have come across a major stumbling block in the code: I've managed to structure the search query but have 2 problems: I dont know how to code the results into the table, and make the table repeat itself 5 times per page (and recognise it needs a new page)
0
10449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.