Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Presenting database info in a table 1

Status
Not open for further replies.

tspeidel

Technical User
Dec 27, 2000
7
US
Im wondering how I can display a list of information from a database into a table. I want the table to be 2 columns wide and as many rows as there is information. I want the info to be displayed across the rows before the next column-Here is what I mean

I want the info from this database:

Bat
Cat
Dog
Mouse

To be displayed in a table as

Bat Cat
Dog Mouse

Any help is appreciated...Thanks!!
 
i would suggest that you read at least the coldfusion manual, as this is described, with a lot of details. The manual can be downloaded at allaire's site i guess
there are also plenty of tutorials that begins with explaining what you are asking for !!!
i mean, don't expect other people to do your job for you; personnaly i'm here to help if you're stuck, not to read the doc for you, not to learn cf for you. The question you're asking is really the BASICS of coldfusion ... maybe someone will be nice enough to answer it ...
 
Well SORRRRRRRRRRRRRRRRYYYYYYYYYYY. Ive looked at the Cold Fusion Manual. I also have The Cold Fusion book written by Ben Forta. Its about 1000 pages. I read the part on CFTABLE and it shows how to list the information like this

Bat
Cat
Mouse
Dog

but it never said anything about placing it the way I wanted it to. Ive been working on Cold Fusion for awhile and I havent gone to a forum once because Ive managed to get myself unstuck. The reason I asked this question is because I couldnt find any information on displaying it the way I wanted to... I guess you didnt read my question CAREFULLY enough and see how I wanted the information presented.

:-(
 
How about something like this:

<table>
<tr>
<cfoutput query=&quot;Test&quot;>
<cfif Test.CurrentRow MOD 2 AND Test.CurrentRow NEQ 1>
</tr>
<tr>
</cfif>
<td>#Trim(Test.Field)#</td>
</cfoutput>
</tr>
</table>

You can use the MOD operator to determine if the current record number is odd or even and create new rows as necessary. Andrew
amayer@sonic.net
 
Hey thanks a lot. You actually read my question unlike iza who was very &quot;snippy&quot; in his reply. I got this to work but there is just a small problem with how it displays. I figure just put all the odds in one column and all the evens in the other, How can I do that?
 
That code should put all the odds in the first column and all the evens in the second. What sort of display problem are you having? Andrew
 
I have a WHERE clause to pull only certain rows from my database and if the database starts on an even row, then it will skip a table entry like this:

Bat *
Cat Mouse
Dog Bird

* - this is where it leaves a blank

Otherwise if it starts with a odd row it works perfectly fine.
 
That's strange... Query.CurrentRow only relates to the total number of records returned by the query. So if your query returned 5 records:

1 | 2
3 | 4
5 |

Maybe it has to do with having an odd number of rows. In that scenario you would only be writing one column on the last table row when the table is setup for two. Try this:

...
</cfif>
<td>#Trim(Test.Field)#</td>
</cfoutput>
<cfif Query.RecordCount NOT Mod 2>
<td>&amp;nbsp;</td>
</cfif>
</tr>
</table>


Maybe that will fix it? Andrew
 
I can have an even or odd number of rows and it will still leave that blank. I tried the thing you suggested in the above post but just got this error:

Just in time compilation error

Invalid parser construct found on line 71 at position 21. Cold Fusion was looking at the following text:

NOT

Hey IZA, I though this was the basics of cold fusion and was in the manual?? Yeah, whatever... Thanks Andrew for all the help
 
Sorry, incorrect syntax... That should have read <cfif NOT Query.RecordCount Mod 2>.

If you're having this problem with both even and odd rows then there is probably a greater evil at work. Post the piece of code you're using and I'll troubleshoot it. I can't seem to reproduce the error you're getting.

Just a quick thought: The query you're using couldn't possibly be pulling a blank record could it? Andrew
 
Still that space. I have no empty records in my database either, I get that blank space on any query that starts on a even row.

Here is my Query at the start:

<CFQUERY DATASOURCE=&quot;store&quot; name=&quot;categories&quot;>
SELECT SubCategoryID, SubCategoryName, ManufacturerID
FROM subcategory
WHERE ManufacturerID = #CategoryID#
</CFQUERY>

And here is the table im trying to make:


<table>
<tr>

<CFOUTPUT QUERY=&quot;categories&quot;>

<CFSET SubcategoryID = #SubCategoryID#>

<CFIF SubCategoryID MOD 2 AND SubCategoryID NEQ 1>
</tr>
<tr>
</CFIF>

<TD><A HREF=&quot;/store/directory.cfm?CategoryID=#SubCategoryID#&quot;>#SubCategoryName#</A></TD>
</CFOUTPUT>

<cfif NOT SubCategoryID Mod 2>
<td>&amp;nbsp;</td>
</cfif>

</tr>

</table>


If you want to see the website in action, I will have it up and running once I get back to school on Wednesday
 
The problem is that you're saying <cfif SubCategoryID MOD 2 AND SubCategoryID NEQ 1>. My guess is that you do not have a record in your SubCategory table that has an ID of 1. You should be using CurrentRow instead since this will always be sequential from 1 to however many records you have.

Get rid of the line <cfset SubCategoryID = #SubCategoryID#> and change the next line to <cfif CurrentRow MOD 2 AND CurrentRow NEQ 1> and everything should work fine. Andrew
 
It worked!! Thank you sooooo much. You were right too, I dont have a record that has an ID of 1. It begins at 100.

Thanks! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top