398,885 Members | 2,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 398,885 IT Pros & Developers. It's quick & easy.

Loop through a recordset and display data in two columns

raevian
P: 6
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
Share this Question
Share on Google+
5 Replies


brettl
P: 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

karlectomy
P: 64
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

raevian
P: 6
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
Expert 100+
P: 1,726
Congratulations on wasting two members valuable time by asking completely the wrong question
Sep 20 '07 #5

karlectomy
P: 64
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

Post your reply

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