473,320 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Echo database results in multiple table rows

I've a piece of code with outputs database results in a table. This is working fine but I want to have max 5 cols and start a new row after that. Would be great if someone could help me out. Many thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. $opties.='<b>'.$option['name'].':</b><br /><table><tr>';
  2.  
  3.       foreach ($option['option_value'] as $option_value) { 
  4.  
  5.         $opties.= '<td><img src="image/cache/'.$option_value['image'].'" /><br />'.$option_value['name'].'</td>';
  6.  
  7.       }
  8.        $opties.='</tr></table>';
Feb 11 '13 #1

✓ answered by Rabbit

Just saying something is wrong doesn't actually give me any info to work with. You have to tell me what's wrong.

As far as your code goes, the one glaring error I see is that line 9 shouldn't be there because you will always need a closing tr tag.

7 1241
Rabbit
12,516 Expert Mod 8TB
Use a variable to keep a column count and if the count is five, write a new row and start the count over.
Feb 11 '13 #2
Thanks for your answer. I tried to use some code snippets I've found on the internet but couldn't get anything to work. :( Could you help me out here? Thanks in advance!
Feb 11 '13 #3
Rabbit
12,516 Expert Mod 8TB
Please post the code you've tried and we can help you fix the problems in your implementation.
Feb 11 '13 #4
Sure here it is:

Expand|Select|Wrap|Line Numbers
  1. $opties.='<b>'.$option['name'].':</b><br /><table><tr>';
  2. $cnt=0;
  3. foreach ($option['option_value'] as $option_value) { 
  4.     if($cnt % 5 == 0 && $cnt > 1) 
  5.         $opties .= '</tr><tr>';
  6.     $opties .= '<td><img src="image/cache/'.$option_value['image'].'" /><br />'.$option_value['name'].'</td>';
  7.     $cnt++;
  8. }
  9. if(count($option['option_value']) % 5 > 0)
  10.     $opties.='</tr>';
  11. $opties.='</table>';
There seems to be something wrong with the rows or cols. It's quit hard to debug because the results of this are send to tcpdf for generating a pdf catalog.
Feb 11 '13 #5
Rabbit
12,516 Expert Mod 8TB
Just saying something is wrong doesn't actually give me any info to work with. You have to tell me what's wrong.

As far as your code goes, the one glaring error I see is that line 9 shouldn't be there because you will always need a closing tr tag.
Feb 11 '13 #6
You did it!! Commented out line 9 and it works! Many, many thanks for this, you made my day!
Feb 11 '13 #7
Rabbit
12,516 Expert Mod 8TB
No problem, glad to help.
Feb 11 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JZ | last post by:
import odbc conn = odbc.odbc('mydsn') c = conn.cursor() c.execute('SELECT TOP 10 field1, field2 FROM TABLE') rows = c.fetchall() c.close() conn.close() I am using MSSQL2000. My problem is:...
1
by: Ray | last post by:
Hello all, I am attempting to delete multiple rows from multiple tables as follows: DELETE FROM attachments,responses,response_lines WHERE attachments.id IN(2,7,11) AND...
12
by: Rick DeBay | last post by:
I'm trying to create a layout table, where the spacing between rows varies. I've tried using setting margin-top and border-top for the rows I wan't spaced down from the one above, and I've also...
4
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
7
by: samoore33 | last post by:
I want to list all of the items in a dataset in a textbox. The dataset has multiple tables. When I try to use the code below, even though I dim myState as the DataTable("state"). It still looks for...
1
by: somaskarthic | last post by:
Hi In my application , i need to create table rows at runtime. Using javascript with table id arguments i could replicate the rows at runtime. Each of these rows has checkboxes (7.no) , dropdown...
1
by: Brave | last post by:
I have MS Access databases that are viewed via ASP pages made in Frontpage. I have two issues that have the same problem. 1: When someone views database results on one of my webpages, and...
0
by: =?Utf-8?B?U3RldmU=?= | last post by:
C# I have a datagrid, and the users are able to select multiple rows and perform an action. This works fine, as I get the rows selected using something like this: CurrencyManager xCM =...
0
by: geraldjr30 | last post by:
hi, i have the following: <html> <STYLE type="text/css"> TD{font-family:ARIAL;font-size:11px;color:#666666;}
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.