Page 1 of 1

Help displaying results in HTML table!

Posted: Tue Jul 16, 2002 8:18 pm
by johnbran
Can someone help a lost newbie! I am trying to display my query results in an HTML table and I can't seem to get it right! I would like to display my information whereas a new table is created for each new category. I can't get this to work at all. The following code doesn't give me what I want. It just lumps everything together. Can someone offer some/any guidance at all on how I can have a new table start over when $ratp_Prod_Title changes?

<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">
<TR>
<?php
while(odbc_fetch_row($odbc_rs)) {
$ratc_Class_Notes=odbc_result($odbc_rs,3);
$ProdID=odbc_result($odbc_rs,4);
$ratp_Prod_Title=odbc_result($odbc_rs,5);
$ratp_Prod_Info=odbc_result($odbc_rs,6);
$ratp_Prod_Notes=odbc_result($odbc_rs,7);
$ratd_Sort_Order=odbc_result($odbc_rs,8);
$ratd_Column01=odbc_result($odbc_rs,9);
$ratd_Column02=odbc_result($odbc_rs,10);
$ratd_Column03=odbc_result($odbc_rs,11);
$ratd_Column04=odbc_result($odbc_rs,12);
$ratd_Column05=odbc_result($odbc_rs,13);
$ratd_Column06=odbc_result($odbc_rs,14);
$ratd_Column07=odbc_result($odbc_rs,15);
$ratd_Column08=odbc_result($odbc_rs,16);
$ratd_Column09=odbc_result($odbc_rs,17);
$ratd_Column10=odbc_result($odbc_rs,18);
$ratd_Notes=odbc_result($odbc_rs,19);
$Rate_Prod_Id=odbc_result($odbc_rs,21);
?>
<TD><?php echo $ratp_Prod_Title;?></TD>
<TD><?php echo $ratp_Prod_Info;?></TD>
</tr>
<tr>
<?php
echo "<TD>$ratd_Column01</TD>";
echo "<TD>$ratd_Column02</TD>";
echo "<TD>$ratd_Column04</TD>";
echo "<TD>$ratd_Column05</TD>";
echo "<TD>$ratd_Column03</TD>";
}
?>
</tr>
</TABLE>
</DIV>
































Posted: Tue Jul 16, 2002 9:03 pm
by ajaypatil
Check out if this is what you want.
Just moved the <tr> tag inside the while loop.

Ajay

Code: Select all

<DIV ALIGN="CENTER"> 
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2"> 
<?php 
while(odbc_fetch_row($odbc_rs)) &#123; 
echo "<tr>";
$ratc_Class_Notes=odbc_result($odbc_rs,3); 
$ProdID=odbc_result($odbc_rs,4); 
$ratp_Prod_Title=odbc_result($odbc_rs,5); 
$ratp_Prod_Info=odbc_result($odbc_rs,6); 
$ratp_Prod_Notes=odbc_result($odbc_rs,7); 
$ratd_Sort_Order=odbc_result($odbc_rs,; 
$ratd_Column01=odbc_result($odbc_rs,9); 
$ratd_Column02=odbc_result($odbc_rs,10); 
$ratd_Column03=odbc_result($odbc_rs,11); 
$ratd_Column04=odbc_result($odbc_rs,12); 
$ratd_Column05=odbc_result($odbc_rs,13); 
$ratd_Column06=odbc_result($odbc_rs,14); 
$ratd_Column07=odbc_result($odbc_rs,15); 
$ratd_Column08=odbc_result($odbc_rs,16); 
$ratd_Column09=odbc_result($odbc_rs,17); 
$ratd_Column10=odbc_result($odbc_rs,1; 
$ratd_Notes=odbc_result($odbc_rs,19); 
$Rate_Prod_Id=odbc_result($odbc_rs,21); 
?> 
<TD><?php echo $ratp_Prod_Title;?></TD> 
<TD><?php echo $ratp_Prod_Info;?></TD> 
</tr> 
<tr> 
<?php 
echo "<TD>$ratd_Column01</TD>"; 
echo "<TD>$ratd_Column02</TD>"; 
echo "<TD>$ratd_Column04</TD>"; 
echo "<TD>$ratd_Column05</TD>"; 
echo "<TD>$ratd_Column03</TD>"; 
echo "</TR>;
&#125; 
?> 
</TABLE> 
</DIV>

Posted: Tue Jul 16, 2002 9:41 pm
by johnbran
I tried your suggestion and I appreciate your time; but unfortunately this doesn't help....I have been working on this for 2 days and no luck...I wonder if it can be done. I wonder if it's possible to dynamically create a table everytime there is a new category....does anyone know if this is possible?

Posted: Tue Jul 16, 2002 10:10 pm
by gnu2php
I think this is what you have in mind. It creates a new table each time the title is different from the previous title.

<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">
<?php
$prev_title = "";

while(odbc_fetch_row($odbc_rs)) {
$ratc_Class_Notes=odbc_result($odbc_rs,3);
$ProdID=odbc_result($odbc_rs,4);
$ratp_Prod_Title=odbc_result($odbc_rs,5);
$ratp_Prod_Info=odbc_result($odbc_rs,6);
$ratp_Prod_Notes=odbc_result($odbc_rs,7);
$ratd_Sort_Order=odbc_result($odbc_rs,8 );
$ratd_Column01=odbc_result($odbc_rs,9);
$ratd_Column02=odbc_result($odbc_rs,10);
$ratd_Column03=odbc_result($odbc_rs,11);
$ratd_Column04=odbc_result($odbc_rs,12);
$ratd_Column05=odbc_result($odbc_rs,13);
$ratd_Column06=odbc_result($odbc_rs,14);
$ratd_Column07=odbc_result($odbc_rs,15);
$ratd_Column08=odbc_result($odbc_rs,16);
$ratd_Column09=odbc_result($odbc_rs,17);
$ratd_Column10=odbc_result($odbc_rs,18 );
$ratd_Notes=odbc_result($odbc_rs,19);
$Rate_Prod_Id=odbc_result($odbc_rs,21);

if ($prev_title && $ratp_Prod_Title != $prev_title)
{
echo "</TABLE>\n";
echo "<br>\n";
echo "<TABLE BORDER=\"1\" WIDTH=\"90%\" CELLPADDING=\"2\">";

$prev_title = $ratp_Prod_Title;
}

?>
<tr>
<TD><?php echo $ratp_Prod_Title;?></TD>
<TD><?php echo $ratp_Prod_Info;?></TD>
</tr>
<tr>
<?php
echo "<TD>$ratd_Column01</TD>";
echo "<TD>$ratd_Column02</TD>";
echo "<TD>$ratd_Column04</TD>";
echo "<TD>$ratd_Column05</TD>";
echo "<TD>$ratd_Column03</TD>";
echo "</tr>";
}
?>
</TABLE>
</DIV>

Posted: Wed Jul 17, 2002 7:36 am
by lc
Ehm... that looks odd to me.. I'd think it'd be:

Code: Select all

<DIV ALIGN="CENTER"> 

<?php 
while(odbc_fetch_row($odbc_rs)) &#123;
 
$ratc_Class_Notes=odbc_result($odbc_rs,3); 
$ProdID=odbc_result($odbc_rs,4); 
$ratp_Prod_Title=odbc_result($odbc_rs,5); 
$ratp_Prod_Info=odbc_result($odbc_rs,6); 
$ratp_Prod_Notes=odbc_result($odbc_rs,7); 
$ratd_Sort_Order=odbc_result($odbc_rs,; 
$ratd_Column01=odbc_result($odbc_rs,9); 
$ratd_Column02=odbc_result($odbc_rs,10); 
$ratd_Column03=odbc_result($odbc_rs,11); 
$ratd_Column04=odbc_result($odbc_rs,12); 
$ratd_Column05=odbc_result($odbc_rs,13); 
$ratd_Column06=odbc_result($odbc_rs,14); 
$ratd_Column07=odbc_result($odbc_rs,15); 
$ratd_Column08=odbc_result($odbc_rs,16); 
$ratd_Column09=odbc_result($odbc_rs,17); 
$ratd_Column10=odbc_result($odbc_rs,1; 
$ratd_Notes=odbc_result($odbc_rs,19); 
$Rate_Prod_Id=odbc_result($odbc_rs,21); 

echo "<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2"><tr>"; 
echo  "<TD> $ratp_Prod_Title</TD>"; 
echo "<TD> $ratp_Prod_Info</TD></tr><tr>"; 

echo "<TD>$ratd_Column01</TD>"; 
echo "<TD>$ratd_Column02</TD>"; 
echo "<TD>$ratd_Column04</TD>"; 
echo "<TD>$ratd_Column05</TD>"; 
echo "<TD>$ratd_Column03</TD>"; 
echo "</tr></TABLE>";
&#125; 
?> 
</DIV>

Posted: Wed Jul 17, 2002 12:13 pm
by johnbran
I tried your suggestion...this is what I got...which unfortunately isn't what I was looking for. It repeats the Title after each row of data. See the example below for a sample of how it should look.

Fixed Mtg Conforming
5.5 6.75 70% Jumbo Loan $250,000
Fixed Mtg Conforming
6.7 7.7 75% Adjustable $300,000
Fixed Mtg Conforming
7.7 8.7 80% Jumbo Loan $350,000
Home Equity Non-conforming
5.5 6.75 70% Jumbo Loan $250,000
Home Equity Non-conforming
6.7 7.7 75% Adjustable $300,000


WHAT I WAS HOPING FOR!

Fixed Mtg Conforming
5.5 6.75 70% Jumbo Loan $250,000
6.7 7.7 75% Adjustable $300,000
7.7 8.7 80% Jumbo Loan $350,000
Home Equity Non-conforming
5.5 6.75 70% Jumbo Loan $250,000
6.7 7.7 75% Adjustable $300,000

[/img]

Posted: Wed Jul 17, 2002 2:02 pm
by gnu2php
:arrow: Try this:

<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

<!-- {<tr> removed} -->

<?php
$prev_title = "";
$prev_info = "";


while(odbc_fetch_row($odbc_rs)) {
$ratc_Class_Notes=odbc_result($odbc_rs,3);
$ProdID=odbc_result($odbc_rs,4);
$ratp_Prod_Title=odbc_result($odbc_rs,5);
$ratp_Prod_Info=odbc_result($odbc_rs,6);
$ratp_Prod_Notes=odbc_result($odbc_rs,7);
$ratd_Sort_Order=odbc_result($odbc_rs,8 );
$ratd_Column01=odbc_result($odbc_rs,9);
$ratd_Column02=odbc_result($odbc_rs,10);
$ratd_Column03=odbc_result($odbc_rs,11);
$ratd_Column04=odbc_result($odbc_rs,12);
$ratd_Column05=odbc_result($odbc_rs,13);
$ratd_Column06=odbc_result($odbc_rs,14);
$ratd_Column07=odbc_result($odbc_rs,15);
$ratd_Column08=odbc_result($odbc_rs,16);
$ratd_Column09=odbc_result($odbc_rs,17);
$ratd_Column10=odbc_result($odbc_rs,18 );
$ratd_Notes=odbc_result($odbc_rs,19);
$Rate_Prod_Id=odbc_result($odbc_rs,21);

if ($ratp_Prod_Title != $prev_title || $ratp_Prod_Info != $prev_info)
{
  • if ($prev_title || $prev_info)
    {
    echo "</TABLE>\n";
    echo "<br>\n";
    echo "<TABLE BORDER=\"1\" WIDTH=\"90%\" CELLPADDING=\"2\">";
    }
echo "<tr>";
echo "<TD>$ratp_Prod_Title</TD>";
echo "<TD>$ratp_Prod_Info</TD>";
echo "</tr>";

$prev_title = $ratp_Prod_Title;
$prev_info = $ratp_Prod_Info;
}

?>

<!-- {SNIP} -->

<tr>
<?php
echo "<TD>$ratd_Column01</TD>";
echo "<TD>$ratd_Column02</TD>";
echo "<TD>$ratd_Column04</TD>";
echo "<TD>$ratd_Column05</TD>";
echo "<TD>$ratd_Column03</TD>";
echo "</tr>";
}
?>

<!-- {</tr> removed} -->

</TABLE>
</DIV>

Posted: Wed Jul 17, 2002 4:37 pm
by johnbran
Oh! My! Goodness!

IT WORKED! IT WORKED!

THANK YOU SOOOOOOO MUCH!!!

I have been working with this for so long that I was close to pulling my hair out. I can actually relax and enjoy the rest of this project.

Thank You again to this board....and to you.


Because, I'm a newbie I don't quite understand what you did...if you could explain what's actually happening with the code I would appreciate it....I understand all of the logic except the removed and snip portions.

Posted: Wed Jul 17, 2002 6:39 pm
by gnu2php
Glad to hear it worked! :wink:

I guess the main thing was that you needed to put </table> and <table> inside the main loop (so that a new table is created). But only print them (and only print the category) if the category is different from the previous one.

Plus, the <tr> and </tr> tags needed to be moved.

The <!-- {SNIP} --> was because I moved the code that displays the category--because it needed to only show the category if it's not the same as the previous one.

Posted: Wed Jul 31, 2002 4:09 pm
by johnbran
I'm now working on a variation to your previous solution and again, I'm having trouble and hoping that you can direct me again. Studying the code it's apparent that a header is created if the Titles are different. What if I wanted to include a row at the end like this:

Fixed Mtg Conforming
5.5 6.75 70% Jumbo Loan $250,000
6.7 7.70 75% Adjustable $300,000
7.7 8.70 80% Jumbo Loan $350,000
**Single family homes only ( I want this to appear)

Home Equity Non-conforming
5.5 6.75 70% Jumbo Loan $250,000
6.7 7.70 75% Adjustable $300,000
**Condominiumns eligible (I want this to appear)

I tried adding the following code to your previous suggestion: My code is in red.

Code: Select all

$prev_title=$ratp_Prod_Title;
$prev_info=$ratp_Prod_Info;

&#125;
?>
<TR>
<?php
		echo "<TD>$ratd_Column01</TD>";
		echo "<TD>$ratd_Column02</TD>";
		echo "<TD>$ratd_Column04</TD>";
		echo "<TD>$ratd_Column05</TD>";
		echo "<TD>$ratd_Column03</TD>";
		echo "</TR>\n";

&#1111;color=red]
echo "<TR>\n";
echo "<TH WIDTH="100%" colspan="9" align="left">$ratp_Prod_Notes</TH>\n";
echo "</TR>";
&#1111;/color]


&#125;
?>
</TABLE>
</DIV>
The above code gives me this:
Fixed Mtg Conforming
5.5 6.75 70% Jumbo Loan $250,000
**Single family homes only
6.7 7.70 75% Adjustable $300,000
**Single family homes only
7.7 8.70 80% Jumbo Loan $350,000
**Single family homes only

Home Equity Non-conforming
5.5 6.75 70% Jumbo Loan $250,000
**Condominiumns eligible
6.7 7.70 75% Adjustable $300,000
**Condominiumns eligible

I also tried adding the same code after the if statements and it worked. ..BUT....it doesn't display properly.

Code: Select all

if($ratp_Prod_Title != $prev_title || $ratp_Prod_Info != $prev_info) &#123;
if($prev_title || $prev_info)&#123;
echo "</TABLE>";

echo "<TABLE BORDER="0" WIDTH="90%" CELLPADDING="2">";
&#125;
echo "<TR>";
echo "<TH WIDTH="100%" colspan="9" 

align="left">$ratp_Prod_Title&nbsp&nbsp$ratp_Prod_Info</TH>\n";
echo "</TR>";

&#1111;color=red]
echo "<TR>";
echo "<TH WIDTH="100%" colspan="9" align="left">$ratp_Prod_Notes</TH>\n";
echo "</TR>";
&#1111;/color]
The above code displays the line at the top under the heading...which isn't what I want. Like such:

Fixed Mtg Conforming
**Single family homes only
5.5 6.75 70% Jumbo Loan $250,000
6.7 7.70 75% Adjustable $300,000
7.7 8.70 80% Jumbo Loan $350,000

Home Equity Non-conforming
**Condominiumns eligible
5.5 6.75 70% Jumbo Loan $250,000
6.7 7.70 75% Adjustable $300,000

I also tried recalling the if statements after the last <TR> but still no luck. So, you see....I really tried. :cry:
Can you guys help me once more....o.k. maybe not just once more... :wink: Cause I'm sure I'll need you all again. Thanks!

Posted: Thu Aug 01, 2002 5:27 am
by gnu2php
:arrow: I haven't tested it, but try this:

<DIV ALIGN="CENTER">
<TABLE BORDER="1" WIDTH="90%" CELLPADDING="2">

<?php
$prev_title = "";
$prev_info = "";
$prev_notes = "";

while(odbc_fetch_row($odbc_rs)) {
$ratc_Class_Notes=odbc_result($odbc_rs,3);
$ProdID=odbc_result($odbc_rs,4);
$ratp_Prod_Title=odbc_result($odbc_rs,5);
$ratp_Prod_Info=odbc_result($odbc_rs,6);
$ratp_Prod_Notes=odbc_result($odbc_rs,7);
$ratd_Sort_Order=odbc_result($odbc_rs,8 );
$ratd_Column01=odbc_result($odbc_rs,9);
$ratd_Column02=odbc_result($odbc_rs,10);
$ratd_Column03=odbc_result($odbc_rs,11);
$ratd_Column04=odbc_result($odbc_rs,12);
$ratd_Column05=odbc_result($odbc_rs,13);
$ratd_Column06=odbc_result($odbc_rs,14);
$ratd_Column07=odbc_result($odbc_rs,15);
$ratd_Column08=odbc_result($odbc_rs,16);
$ratd_Column09=odbc_result($odbc_rs,17);
$ratd_Column10=odbc_result($odbc_rs,18 );
$ratd_Notes=odbc_result($odbc_rs,19);
$Rate_Prod_Id=odbc_result($odbc_rs,21);

if ($ratp_Prod_Title != $prev_title || $ratp_Prod_Info != $prev_info)
{
if ($prev_title || $prev_info)
{
if ($prev_notes)
{
echo "<tr>";
echo "<TH width=\"100%\" colspan=\"9\">$prev_notes</TH>";
echo "</tr>";
}

echo "</TABLE>\n";
echo "<br>\n";
echo "<TABLE BORDER=\"1\" WIDTH=\"90%\" CELLPADDING=\"2\">";
}
echo "<tr>";
echo "<TD>$ratp_Prod_Title</TD>";
echo "<TD>$ratp_Prod_Info</TD>";
echo "</tr>";

$prev_title = $ratp_Prod_Title;
$prev_info = $ratp_Prod_Info;
$prev_notes = $ratp_Prod_Notes;
}
?>

<tr>
<?php
echo "<TD>$ratd_Column01</TD>";
echo "<TD>$ratd_Column02</TD>";
echo "<TD>$ratd_Column04</TD>";
echo "<TD>$ratd_Column05</TD>";
echo "<TD>$ratd_Column03</TD>";
echo "</tr>";
}
?>

</TABLE>
</DIV>

Posted: Mon Aug 05, 2002 1:55 pm
by johnbran
Thank you again....it worked beautifully!

I'm beginning to believe that trying to wing it isn't going to cut it. I need to take a class. From looking at your code I should have been able to figure this one out based on your previous assistance. I'm missing something concepts or logic wise regarding this language. But I'll keep trying.

Thank you again for your help.