By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,192 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,192 IT Pros & Developers. It's quick & easy.

Display sql query output in html table

P: n/a
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_array($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
Share this Question
Share on Google+
2 Replies


P: n/a
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_array($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_array($result, MYSQL_ASSOC)) {
if ($row['cat'] != $cat) {
echo $row['cat'] . ' ';
$cat = $row['cat'];
}
echo 'Class: ' . $row['title'] . "Description" . $row['desc'];
}

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 24 '06 #2

P: n/a
That did the trick thanks much for the input.

--

Regards,

Jerry M. Gartner

"Jerry Stuckle" <js*******@attglobal.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_array($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_array($result, MYSQL_ASSOC)) {
if ($row['cat'] != $cat) {
echo $row['cat'] . ' ';
$cat = $row['cat'];
}
echo 'Class: ' . $row['title'] . "Description" . $row['desc'];
}

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

Jun 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.