Solved

Vertical looper with only 2 colums

Posted on 2008-06-17
7
291 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

929 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

8 Experts available now in Live!

Get 1:1 Help Now