Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Vertical looper with only 2 colums

Posted on 2008-06-17
7
Medium Priority
?
341 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 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 

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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

916 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