473,386 Members | 1,810 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,386 software developers and data experts.

Loop through a recordset and display data in two columns

Hi, I have a table made up of two columns. I want to loop through a recordset and display the data in the two columns. How would you do this??

thanks!
Sep 19 '07 #1
5 13433
brettl
41
I'm not sure if this is what you're asking for.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. $data = array( array(
  4.         col1 => 'col1a',
  5.         col2 => 'col2a',
  6.     ),
  7.         array(
  8.         col1 => 'col1b',
  9.         col2 => 'col2b',
  10.     ),
  11.         array(
  12.         col1 => 'col1c',
  13.         col2 => 'col2c',
  14.     ),
  15.         array(
  16.         col1 => 'col1d',
  17.         col2 => 'col2d'
  18.     )
  19.     );
  20.  
  21.  
  22. ?>
  23.  
  24.  
  25. <table>
  26.     <tr>
  27.         <td> Column1 </td>
  28.         <td> Column2 </td>
  29.     </tr>
  30.  
  31. <?php
  32. foreach ($data as $hit) {
  33.  
  34.     print <<< _HTML_
  35.         <tr>
  36.             <td>$hit[col1]</td>
  37.             <td>$hit[col2]</td>
  38.         </tr>
  39. _HTML_;
  40. }
  41. ?></table>    
  42.  
Sep 19 '07 #2
This might be a little faster.

$result = mysql_query($quString);
$row = mysql_fetch_assoc($result);

echo("<table><tr><td>Column 1</td><td>Column 2</td></tr>");

for($i = 0; $i < sizeof($arr); $i++)
{
echo("<tr><td>$row[$i]['Col1name']</td><td>".$row[$i]['Col2name']."</td></tr>");
}
echo("</table>");
Sep 19 '07 #3
thanks for the reply.but i am going to get the data from the same column in the database and display them in two columns in my html table. help please.thanks!
Sep 20 '07 #4
code green
1,726 Expert 1GB
Congratulations on wasting two members valuable time by asking completely the wrong question
Sep 20 '07 #5
I'm really confused: why would you want the same data in two columns in the same table?

anyways, Here's some code

[PHP]
$result = mysql_query($quString);
$row = mysql_fetch_assoc($result);

echo("<table><tr><td>Column 1</td><td>Column 1 Again?</td></tr>");

for($i = 0; $i < sizeof($arr); $i++)
{
echo("<tr><td>$row[$i]['Col1name']</td><td>".$row[$i]['Col1name']."</td></tr>");
}
echo("</table>");
[/PHP]
Sep 20 '07 #6

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

Similar topics

0
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
4
by: Bryan | last post by:
I have a results table that is 5 columns wide. the recordset is returned with 48 items. I have no problem displaying 5 per row until I hit the last row where i get a ADODB.Field error '80020009' ...
3
by: addi | last post by:
All, I will be eternally greatful if someone can provide snippet of code, URL or reference material that shows how to display data in a "n colums * n rows" format. I am new to ASP and have...
2
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
0
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a...
20
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into...
2
by: Lyn | last post by:
Hi, I am opening a form in Continuous mode to list the records from a recordset created in the calling form. The recordset object is declared as Public and is set into the new form's Recordset...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
daniel aristidou
by: daniel aristidou | last post by:
Hi i wrote code to print records off a datagrid.the code works on all but one of my data grids. The problem is that loop continues without stopping, Causing the program to crash. The only diff...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.