Solved

Vertical looper with only 2 colums

Posted on 2008-06-17
7
281 Views
Last Modified: 2013-12-12
I have a vertical looper that shows the records in alphabetical order in my code if i have more than 40 records it creates a new colum. what i need is the code below to show 50% of the records or all in two colums. I tried a horzontal looper but that changes the alpha order. here is the code im using.

------------------code-------------------
<?php
$rows_RsAdvertise = 40;
$cols_RsAdvertise = ceil($totalRows_RsAdvertise/ 40);
for ($i=0; $i<$rows_RsAdvertise; $i++) {
      for ($j=0; $j<$cols_RsAdvertise; $j++) {
            $currentIndex_RsAdvertise = $i + $rows_RsAdvertise * $j;
            if (@mysql_data_seek($RsAdvertise, $currentIndex_RsAdvertise)) {
                  $row_RsAdvertise = mysql_fetch_assoc($RsAdvertise);
?>
0
Comment
Question by:romarc
  • 4
  • 2
7 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 500 total points
ID: 21810029
Like this?
<?php

$cols_RsAdvertise = 2;

$rows_RsAdvertise = ceil($totalRows_RsAdvertise/ $col_RsAdvertise);

for ($i=0; $i<$rows_RsAdvertise; $i++) {

      for ($j=0; $j<$cols_RsAdvertise; $j++) {

            $currentIndex_RsAdvertise = $i + $rows_RsAdvertise * $j;

            if (@mysql_data_seek($RsAdvertise, $currentIndex_RsAdvertise)) {

                  $row_RsAdvertise = mysql_fetch_assoc($RsAdvertise);

// I assume in here you display the record

?>

Open in new window

0
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 21810044
Is this what you looking for ?

Bonmat86.
<table width="200" border="0" align="center">

<?php

$n = 13;

$max = ceil(13/2);

$max_n = $max;

for ($i = 1; $i <= $max; $i++)

{

	$table .= '<tr><td align="center">' . $i . '</td>';

	($max_n + $i <= $n) ? $table .= '<td align="center">' . ($max_n + $i) . '</td></tr>' : '';

}

echo $table;

?>

</table>

Open in new window

0
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 21810056
@Michael701: Oh, I didn't see your post.

Btw, at my code
$max = ceil(13/2);
should change to
$max = ceil($n/2);

Bonmat86.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

Author Comment

by:romarc
ID: 21818820
Michael701
that code dawns an error
Warning: Division by zero in ...

the code i posted works but if i go over 40 records it creates a new column. i need it to display only 2 columns showing all records.
0
 

Author Comment

by:romarc
ID: 21818836
Ok i got it there was a typo on line 3 of bonmat86: code
$col_RsAdvertise s/b $cols_RsAdvertise

now it works
Thanks
0
 

Author Closing Comment

by:romarc
ID: 31468188
Thanks, sorry for the delay but there was a typo in the thrid line $col_RsAdvertise   i changed to $cols_RsAdvertise and it works now
0
 

Author Comment

by:romarc
ID: 21818849
sorry bonmat86:
not your code but Michael701: code had the typo
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now