Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Multiple Table Rows in "while" loop
Old 09-26-2007, 08:44 AM Multiple Table Rows in "while" loop
Junior Talker

Posts: 1
Trades: 0
I have the code below with two table rows, but the second row won't display any data. How can I make both table rows work? Is it even possible to have multiple tables in a "while" loop?

Sara

PHP Code:
echo "<table cellpadding=\'2\' cellspacing=\'0\'>"

echo 
"<tr>"
echo 
"<td class=\"th\" >COL1</td>"
echo 
"<td class=\"th\" >COL2</td>"
echo 
"<td class=\"th\" >COL3</td>"
echo 
"</tr>"

$rowcount 0
$group1_current_row 0
$group2_current_row 0
$group3_current_row 0
$group4_current_row 0
$group5_current_row 0
$grouptotal_current_row 0
$isStart01 0
$isStart02 0
$isStart03 0
$isStart04 0
$isStart05 0

while (
$row mysql_fetch_array($result)) { 

  if (
$rowcount == 0) { 
  } 
  
$newgroupindex = -1
    echo 
"<tr>";//this row displays multiple rows 
    
if (($rowcount%2) == 0) { 
        
$css_class "\"one\""
    } else { 
        
$css_class "\"two\""
    } 
    
$cellvalue "" $row[1] . ""
    if (
$cellvalue == "") { 
        
$cellvalue "&nbsp;"
    } 
    echo 
"<td class=" $css_class "   align=Default >" $cellvalue "</td>"
    
$cellvalue "" $row[2] . ""
    if (
$cellvalue == "") { 
        
$cellvalue "&nbsp;"
    } 
    echo 
"<td class=" $css_class "   align=Default >" $cellvalue "</td>"
    
$cellvalue "" $row[3] . ""
    if (
$cellvalue == "") { 
        
$cellvalue "&nbsp;"
    } 
    echo 
"</tr>"
     
     
     
    echo 
"<tr>";//this is the new row that should only display the row of data once 
    
echo "<td class=" $css_class "   align=Default >" $cellvalue "</td>"
    
$cellvalue "" $row[4] . ""
    if (
$cellvalue == "") { 
        
$cellvalue "&nbsp;"
    } 
    echo 
"<td class=" $css_class "   align=Default >" $cellvalue "</td>"
    
$cellvalue "" $row[5] . ""
    if (
$cellvalue == "") { 
        
$cellvalue "&nbsp;"
    } 
    echo 
"<td class=" $css_class "   align=Default >" $cellvalue "</td>"
    
$cellvalue "" $row[6] . ""
    if (
$cellvalue == "") { 
        
$cellvalue "&nbsp;"
    } 
    echo 
"</tr>"
     
  
$newgroupindex = -1
  
$rowcount $rowcount 1
    
$isStart01++; 
    
$isStart02++; 
    
$isStart03++; 
    
$isStart04++; 
    
$isStart05++; 


echo 
"</table>"
user55 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-26-2007, 10:53 AM Re: Multiple Table Rows in "while" loop
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Your problem is that you use the $cellvalue of the previous statement each time.
No offense, but you are making a simple task hard to read there.
I've rewrote this little code like this, and replaced the mysql datas by a generated array:
PHP Code:
 
<?php
echo "<table cellpadding=\'2\' cellspacing=\'0\'>"
 
echo 
"<tr>"
echo 
"<td class=\"th\" >COL1</td>"
echo 
"<td class=\"th\" >COL2</td>"
echo 
"<td class=\"th\" >COL3</td>"
echo 
"</tr>"
 
$rowcount 0
$group1_current_row 0
$group2_current_row 0
$group3_current_row 0
$group4_current_row 0
$group5_current_row 0
$grouptotal_current_row 0
$isStart01 0
$isStart02 0
$isStart03 0
$isStart04 0
$isStart05 0
 
//while ($row = mysql_fetch_array($result)) {
 
for($i=1;$i<=10;$i++){
    
$records[$i][1]="$i::aaa";
    
$records[$i][2]="$i::bbb";
    
$records[$i][3]="$i::ccc";
    
$records[$i][4]="$i::ddd";
    
$records[$i][5]="$i::eee";
    
$records[$i][6]="$i::fff";
}
foreach(
$records as $row){
  if (
$rowcount == 0) { 
      
$newgroupindex = -1
      
$css_class=(($rowcount%2) == 0)?"one":"two";
      echo<<<HTML
<tr>
    <td class="
$css_class" align="default">
        
{$row[1]}
    </td>
    <td class="
$css_class" align="default">
        
{$row[2]}
    </td>
    <td class="
$css_class" align="default">
        
{$row[3]}
    </td>
</tr>
HTML;
    
$newgroupindex = -1
    
$rowcount $rowcount 1
    
$isStart01++; 
    
$isStart02++; 
    
$isStart03++; 
    
$isStart04++; 
    
$isStart05++; 
  }

echo 
"</table>";  
?>
Why would do 6 time "echo '<td...." when you can do everything into 1 echo.
And if you still have only 1 row, it surely means that your problem is in the sql query that provides you the datas, and not in the logic.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 09-26-2007 at 10:55 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Multiple Table Rows in "while" loop
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10136 seconds with 12 queries