473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I return 3 results and print </tr>

I am trying to build a table using results from a database query.
Right now (code below), the code displays each result in a new <tr>. I
am wanted to display 3 results in one <tr> </tr>, and then create a new
<tr> with another 3, etc.

Here is human code:
print a <tr>
if only 1, 2 or 3 results have been returned, show the results and
print a </tr>
if 4, 5, and or 6 results have been returned, print <tr> and show
results
if no more results have been returned, print </tr>

Does that make sense? Can anyone help?

Thank you
Here is my PG query (function):
###############
function section_get_sec tions() {
$dbconn = sys_db_connect( );
if ($dbconn == FALSE) {
return NULL;
}

$dbquery = <<<EOB
SELECT section.id, section.name
FROM section
ORDER BY section.name

EOB;

$dbresult = sys_db_query ($dbconn, $dbquery);
if ($dbresult == FALSE) {
return NULL;
} else {
return $dbresult;
}
}
###############
Here is my PHP current code displaying the results:
###############
EOB;
$r = section_get_sec tions();
for ($i = 0; $i < pg_numrows($r); $i++) {
$t = pg_fetch_assoc( $r, $i);
print <<<EOB
<tr>
<td class="fe_label " nowrap>
{$t['name']}
</td>
<td class="fe_widge t">
<input name="sections[]" type="checkbox" value="{$t['id']}"
EOB;
if (in_array($t['id'], $fd['sections'])) {
echo(" checked");
}
print <<<EOB

</td>
</tr>
###############

Jul 17 '05 #1
4 2178
*** Aaron Reimann wrote/escribió (31 May 2005 07:55:35 -0700):
I am trying to build a table using results from a database query.
Right now (code below), the code displays each result in a new <tr>. I
am wanted to display 3 results in one <tr> </tr>, and then create a new
<tr> with another 3, etc.


$position=0;

while( ... ){
if($position==0 ){
echo '<tr>';
}

echo '<td>' . $data . '</td>';

if($position==2 ){
echo '</tr>';
}

$position=($pos ition+1) % 3;
}
We leave completing last line as an exercise for the reader ;-)

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2
"Aaron Reimann" <aa***********@ gmail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I am trying to build a table using results from a database query.
Right now (code below), the code displays each result in a new <tr>. I
am wanted to display 3 results in one <tr> </tr>, and then create a new
<tr> with another 3, etc.

Here is human code:
print a <tr>
if only 1, 2 or 3 results have been returned, show the results and
print a </tr>
if 4, 5, and or 6 results have been returned, print <tr> and show
results
if no more results have been returned, print </tr>

Does that make sense? Can anyone help?

Try something like this:

echo "<tr>";
for ($i = 0; $i < pg_numrows($r); $i++) {
echo "<td>";
// output your info here
echo "</td>";
if ( ( $i + 1 ) % 3 == 0 ) { echo "</tr><tr>"; }
}
echo "</tr>";


Jul 17 '05 #3
Try something like this:

echo "<tr>";
for ($i = 0; $i < pg_numrows($r); $i++) {
echo "<td>";
// output your info here
echo "</td>";
if ( ( $i + 1 ) % 3 == 0 ) { echo "</tr><tr>"; }
}
echo "</tr>";


Thank you. That works for me.

Sorry about the late reply.

Jul 17 '05 #4

"Aaron Reimann" <aa***********@ gmail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
Try something like this:

echo "<tr>";
for ($i = 0; $i < pg_numrows($r); $i++) {
echo "<td>";
// output your info here
echo "</td>";
if ( ( $i + 1 ) % 3 == 0 ) { echo "</tr><tr>"; }
}
echo "</tr>";


Thank you. That works for me.

Sorry about the late reply.


Glad I could help :)
Jul 17 '05 #5

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

Similar topics

2
3209
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
2
3657
by: John Geddes | last post by:
In both IE6 and Netscape 7: insertRow method of tbody is behaving as expected: - inserts a new row - increases tbody.rows.length BUT deleteRow is not doing the opposite. It DOES delete the row, but it adds a <TR></TR> pair just before the </TBODY> and that leaves the tbody.rows.length count unchanged.
7
2116
by: F. Da Costa | last post by:
Hi, I' looking to retrieve ProdName1 form the <tr> below. <tr id="1-1-1" class="even"> <td> <div class="tier4"> <a href="#" class="leaf"></a> ProdName1 </div>
4
7241
by: El Diablo | last post by:
Hi there, I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment: theTable.tHead.appendChild(document.createElement('TR')) ....but this only gives me table rows with no table data cells. So I would like to know if it's possible to create several <TH> within the tHead row using this method?
1
2222
by: prefersgolfing | last post by:
I'm not using Master Pages, yet I'd like to display the contents of an HTML page within a <table><tr><td> on a .aspx. I have a lengthy guide already paginated in html. I'd like to embed the pages "as is" in the new 2.0 app without using Master Pages or creating new ..aspx's. I'm looking for the quickest way to the finish line. Any suggestions would be welcomed. Thanks.
2
2673
by: petereffect | last post by:
i have foll. code <tr> <a href="a1.shtml"> <td width='100%'> &nbsp;"+Testing+ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td> </a>
5
2933
by: mahesr | last post by:
I want to match some particular text between <tr>and </tr> or <td>and </td>.... in PHP. like below............ <table><tr> CATEGORY: <td><font face="Verdana" size="1" color="#A000A0"> Wedding Accessories
3
3367
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
7
2782
by: Xiaoyan | last post by:
Hi,everyone: I have a problem now. I can't get the information between the <tr><td> and </td></tr>. for example: I use this regular expression can't get it, I don't know why. $test=~/<tr><td>(.*)<\/td><\/td>(.*)<\/td><\/tr>/ms; <tr><td>station</td> <td>station number/identification, see chart above: <br> B = GoMoos buoy B location<br> S = New Scantum at the southern edge Jefferys Ledge</td></tr>.
0
8310
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
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
8732
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
8503
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
7330
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
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
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.