Solved

Vertical looper with only 2 colums

Posted on 2008-06-17
7
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 …

756 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