-2

I want to display records from database in this order

1 2 3
4 5 6
........


or


1 4 ....
2 5 ...
3 6.....

pls can anybody help me ........

Edited by kiranhg.2008: n/a

Votes + Comments
Don't hijack threads. Always start a new thread.
4
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by kiranhg.2008
0

I want to display records from database in this order

1 2 3
4 5 6
........


or


1 4 ....
2 5 ...
3 6.....

pls can anybody help me ........

Not much use putting that info in this solved topic. Try setting up a new topic.

-1
<?php while ($prows = mysql_fetch_array($rs_pending)) {?>
    <tr> 
          <td>#<?php echo $prows['id']?></td>
          <td><?php echo $prows['NameOfCompany']?></td>
          <td><?php echo $prows['emailId']?></td>
          <td><?php echo $prows['Category']?></td>
          <td><?php echo $prows['Activity']?></td>
          <td><?php echo $prows['Address']?></td>
          <td><?php echo $prows['Phone']?></td>
          <td><?php echo $prows['Fax']?></td>
          <td><?php echo $prows['Website']?></td>
    </tr>
        <?php } ?>

this will display records in this order normally
1
2
3
.
.


But my query is i want 2 display records in this order..

1 2 3
4 5 6
.........

or

1 4 . . .
2 5 . . .
3 6. . .


pls anybody help me...if u any idea r code send it.....
3

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

1

a simple solution to this can be to use a counter for ur loop and check to introduce a new <tr> when its in multiples of 3(or 2 watever the num of columns u r lookin for).
something like this...

<?php $counter =0;
    while ($prows = mysql_fetch_array($rs_pending)) {
       if (($counter%3) == 0)){  ?>
          <tr> 
       <?php } ?>
          <td><?php echo $prows['id']?></td>
          <td><?php echo $prows['NameOfCompany']?></td>
          <td><?php echo $prows['emailId']?></td>
          <td><?php echo $prows['Category']?></td>
          <td><?php echo $prows['Activity']?></td>
          <td><?php echo $prows['Address']?></td>
          <td><?php echo $prows['Phone']?></td>
          <td><?php echo $prows['Fax']?></td>
          <td><?php echo $prows['Website']?></td>
     if (($counter%3) == 0)){  ?>
         </tr> 
     <?php } ?>
        <?php $counter++; } ?>

<?php while ($prows = mysql_fetch_array($rs_pending)) {?>
<tr>
<td>#<?php echo $prows?></td>
<td><?php echo $prows?></td>
<td><?php echo $prows?></td>
<td><?php echo $prows?></td>
<td><?php echo $prows?></td>
<td><?php echo $prows?></td>
<td><?php echo $prows?></td>
<td><?php echo $prows?></td>
<td><?php echo $prows?></td>
</tr>
<?php } ?>


this will display records in this order normally
1
2
3
.
.


But my query is i want 2 display records in this order..

1 2 3
4 5 6
.........

or

1 4 . . .
2 5 . . .
3 6. . .


pls anybody help me...if u any idea r code send it.....
3

open up a new thread if u face some problems, no 1 is going to reply here anymore..
This thread is already solved

Edited by venkat0904: n/a

0

Following code is for 3 columns and n no of rows. it will print you ID as
1 2 3
4 5 6
....

<?php 
	$isrowopen=false;
	$totalrows=0;
	while ($prows = mysql_fetch_array($rs_pending)) 
	{   
		$totalrows++;
		if((($totalrows)%3)==1)
		{
		     print "\n<tr>";
	          $isrowopen=true;			     
	    }
	    ?>
	
	    <td>#<?php echo $prows['id']?></td>

	    <?php
		if((($totalrows)%3)==0)
		{			
		     print "\n</tr>";
			$isrowopen=false;						
		} 
	}         
	
	if ($isrowopen && (($totalrows)%3)==1)
			print "\n\t\t<td>&nbsp;</td><td>&nbsp;</td></tr>";	     
	else if ($isrowopen && (($totalrows)%3)==2)
		print "\n\t\t<td>&nbsp;</td></tr>";	     
?>
0

Following code is for 3 columns and n no of rows. it will print you ID as
1 2 3
4 5 6
....

<?php 
	$isrowopen=false;
	$totalrows=0;
	while ($prows = mysql_fetch_array($rs_pending)) 
	{   
		$totalrows++;
		if((($totalrows)%3)==1)
		{
		     print "\n<tr>";
	          $isrowopen=true;			     
	    }
	    ?>
	
	    <td>#<?php echo $prows['id']?></td>

	    <?php
		if((($totalrows)%3)==0)
		{			
		     print "\n</tr>";
			$isrowopen=false;						
		} 
	}         
	
	if ($isrowopen && (($totalrows)%3)==1)
			print "\n\t\t<td>&nbsp;</td><td>&nbsp;</td></tr>";	     
	else if ($isrowopen && (($totalrows)%3)==2)
		print "\n\t\t<td>&nbsp;</td></tr>";	     
?>

tanhx.......I appreciate..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.