Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Vertical looper with only 2 colums

Posted on 2008-06-17
7
Medium Priority
?
332 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 2000 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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…

722 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