RE: [PHP-DB] Re: php-db Digest 8 Mar 2004 20:50:10 -0000 Issue 2294
| From: | Aleks @ USA.net | Date: | Mon, 08 Mar 2004 22:04:47 +0000 |
| Subject: | RE: [PHP-DB] Re: php-db Digest 8 Mar 2004 20:50:10 -0000 Issue 2294 | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-33370@lists.php.net to get a copy of this message | ||
HI Frank,
Thank you for the suggestion.. I think I see where you are going with
this...
However, how do I update the $oldCat with the last ProdCategory printed so
that
It will print the next new Category found in the while statement.??
-----Original Message-----
From: Frank Flynn [mailto:frank@declan.com]
Sent: Monday, March 08, 2004 4:11 PM
To: php-db@lists.php.net; aleks.k@usa.net
Subject: [PHP-DB] Re: php-db Digest 8 Mar 2004 20:50:10 -0000 Issue 2294
Not a nested array, a simple 'if' statement...
Something like:
$Info = mysql_query("SELECT .....
$oldCat = "";
while ($SRecord = mysql_fetch_array($Info, MYSQL_ASSOC)) {
If $oldCat != $SRecord["ProdCategory"]
{
/* Print your special Header row */
echo "<TR><TD>Category = $Category </TD></TR>";
}
/* now all you need is $Model - $Description - $Price */
$Model = htmlspecialchars($SRecord["ItemModel"]);
$Description = htmlspecialchars($SRecord["ItemDescription"]);
$Price = htmlspecialchars($SRecord["ItemPrice"]);
?>
<tr>
<td><font face="Arial" size="-1"><? echo("$Model");
?></font></td>
<td><font face="Arial" size="-1"><?
echo("$Description"); ?></font></td>
<td><font face="Arial" size="-1"><? echo("$Price");
?></font></td> <?
}
?>
Good Luck,
Frank
On 3/8/04 12:50 PM, "php-db-digest-help@lists.php.net"
<php-db-digest-help@lists.php.net> wrote:
>
> From: "Aleks @ USA.net" <aleks.k@usa.net>
> Reply-To: <aleks.k@usa.net>
> Date: Mon, 8 Mar 2004 15:50:01 -0500
> To: "PHPDatabase List" <php-db@lists.php.net>
> Subject: Group inner join results
>
> Hi all,
>
> I thought I saw the answer to this question on here but can not find
> the answer ..
> So,
>
> I am doing an inner join on 2 tables and displaying the result as follows:
>
> Code=========================================================
> <table cellspacing="2" cellpadding="2" border="0">
> <tr> <td><font
> face="Arial" size="-1"><b>Cat#</b></font></td>
> <td><font face="Arial"
> size="-1"><b>Category</b></font></td>
> <td><font face="Arial"
> size="-1"><b>Model</b></font></td>
> <td><font face="Arial"
> size="-1"><b>Description</b></font></td>
> <td><font face="Arial"
> size="-1"><b>Price</b></font></td>
>
> </tr>
> <?
>
> $Info = mysql_query("SELECT Table1.CatID, Table1.ProdCategory,
> Table2.ItemID, Table2.ItemDescription, Table2.ItemModel,
> Table2.ItemPrice FROM Table1 LEFT OUTER JOIN Table2 ON
> Table1.CatID=Table2.CatID ORDER BY Table2.ItemID");
>
> while ($SRecord = mysql_fetch_array($Info, MYSQL_ASSOC)) {
>
> $CatID = htmlspecialchars($SRecord["CatID"]);
> $Category = htmlspecialchars($SRecord["ProdCategory"]);
> $Model = htmlspecialchars($SRecord["ItemModel"]);
> $Description = htmlspecialchars($SRecord["ItemDescription"]);
> $Price = htmlspecialchars($SRecord["ItemPrice"]);
>
> ?>
>
> <tr>
> <Td><font face="Arial" size="-1"><? echo
> ("$CatID");
> ?></FONT></A></td> <td><font face="Arial"
> size="-1"><?
> echo("$Category"); ?></font></td> <td><font
> face="Arial" size="-1"><?
> echo("$Model"); ?></font></td> <td><font
> face="Arial" size="-1"><?
> echo("$Description"); ?></font></td> <td><font
> face="Arial"
> size="-1"><? echo("$Price"); ?></font></td> <?
> }
> ?>
>
> </tr></table>
>
> Code==================================================================
> ====
>
> The output of above is
>
> ----------------------------------------------------------------------
> ------
> -
> | Cat# | Category | Model | Description | Price
> ----------------------------------------------------------------------
> ------
> -
> | $CatID | $Category | $Model | $Description | $Price
> ----------------------------------------------------------------------
> ------
> --
>
>
> What I need to do is build a table display where the output is grouped
> by Category.
>
> Like this:
>
> ---------------------------------------------------
> | Category = Ist $Category
> ---------------------------------------------------
> | $Model - $Description - $Price
> ---------------------------------------------------
> | Category = 2nd $Category
> ---------------------------------------------------
> | $Model - $Description - $Price
> ---------------------------------------------------
> | Category = 3rd $Category
> ---------------------------------------------------
> | $Model - $Description - $Price
> -----------------------------------------------------
>
> I think that I can do this
> with a nested array... anyone have an idea??
>
> THanks in advance...
>
> Aleks
--
Frank Flynn
Poet, Artist & Mystic
--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php