Forums

PHP

This topic is locked

Is there a Vertical Looper?

Posted 05 Mar 2004 02:20:28
1
has voted
05 Mar 2004 02:20:28 Robert Kruse posted:
Does anyone know how to set up a repeat region that will display your recordset results in multiple columns rather than a single column or multiple rows (via Horizonal Looper)?

Just thought I'd throw the question out there.

Thanks,

Replies

Replied 10 Mar 2004 03:08:57
10 Mar 2004 03:08:57 Phil Shevlin replied:
There is a horiz looper out there by Thomas Muck
Replied 18 Mar 2004 11:02:09
18 Mar 2004 11:02:09 Greta Garberini replied:
THomas Muck has the extension called simulated nested repeat. It is cool if you have a flatfile record with categories and articles and you don't want to show the category again and again with each article belonging to it.
There is a horizontal looper at felixone.it
You can specify how many columns you want. Cool extension, although commercial. But much cheaper than the DMX zone ones.
Replied 18 Mar 2004 16:18:24
18 Mar 2004 16:18:24 Robert Kruse replied:
I'm sorry if I didn't explain correctly, I was looking for something other than the Horizonal Looper since it only loops multiple rows "left to right"...

EX.
A B C D E F G
H I J K L M N
O P Z R S T U
V W X Y Z

A Vertical looper would make multiple columns "top to bottom" EX..

A H O V
B I P W
C J Q X
D K R Y
E L S Z
F M T
G N U

(sorry for the poor formatting but you get the idea)


Any ideas on how to pull this off?
Replied 20 Mar 2004 20:48:44
20 Mar 2004 20:48:44 Phil Shevlin replied:
I'm confused. Rows go from top to bottom. Columns go from left to right.
Replied 20 Mar 2004 21:15:12
20 Mar 2004 21:15:12 Robert Kruse replied:
The data in a row is displayed left to right. The data in a column is displayed top to bottom.

For example, if you had a recordset of food ordered alphabetically and wanted to output it to two columns like...

column #1____ column #2
apples________eggs
bananas_______ham
carrots________peanuts
coffee________potato

(once again excuse the formatting, the underscores ___ are meant to be blank space)

How would you do it?
Replied 20 Mar 2004 21:55:36
20 Mar 2004 21:55:36 Phil Shevlin replied:
Seems like you are asking to do a basic dynamic table. If thats the case try: <pre id=code><font face=courier size=2 id=code>&lt;?php
mysql_select_db($database_cn, $cn);
$query_RS = "SELECT * FROM myTable";
$RS = mysql_query($query_RS, $cn) or die(mysql_error());
$row_RS = mysql_fetch_assoc($RS);
$totalRows_RS = mysql_num_rows($RS);
?&gt;
&lt;table border="0" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;column 1&lt;/td&gt;
&lt;td&gt;column 2&lt;/td&gt;
&lt;/tr&gt;
&lt;?php do { ?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;?php echo $row_RS['fieldOne']; ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $row_RS['fieldTwo']; ?&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php } while ($row_RS = mysql_fetch_assoc($RS)); ?&gt;
&lt;/table&gt;
&lt;?php
mysql_free_result($RS);
?&gt; </font id=code></pre id=code>
Replied 20 Mar 2004 22:37:47
20 Mar 2004 22:37:47 Robert Kruse replied:
Sorry, I think we're misintreperting each others terminology and the idea is not coming across right.

Your solution was using 2 different fields from the database, and displaying them straight down the page.

From the database we're only working with 1 column (FoodName), on the webpage we want to put all of different FoodName records in alphabetical order
"SELECT FoodName FROM FoodTable ORDER BY FoodName ASC", then display the results in a 2 or more column format as illustrated in my previous message.

Does this make sense?

column #1____ column #2
apples________eggs
bananas_______ham
carrots________peanuts
coffee________potato

or

col___________col_______col
apples________coffee_____potato
bananas______ eggs
carrots_______ peanuts
Replied 21 Mar 2004 04:02:17
21 Mar 2004 04:02:17 Phil Shevlin replied:
I was curious myself. Just spent 2 hours playing with it. Merry Xmas <pre id=code><font face=courier size=2 id=code>&lt;?php require_once('Connections/conn.php'); ?&gt;
&lt;?php
mysql_select_db($database_conn, $conn);
$query_rs = "SELECT FoodName FROM FoodTable ORDER BY FoodName ASC";
$rs = mysql_query($query_rs, $conn) or die(mysql_error());
$row_rs = mysql_fetch_assoc($rs);
$totalRows_rs = mysql_num_rows($rs);
?&gt;
&lt;!-- body tags--&gt;
&lt;?php
$number_columns = 8; // manually set the number of columns
$break_point = ceil($totalRows_rs / $number_columns); // divide total rows by 3 to find break points
$counter = 0; // start a counter
?&gt;
&lt;table border="0" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td colspan="&lt;?php echo $number_columns; ?&gt;" align="center"&gt;Column header&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top"&gt;
&lt;?php
do {
$counter++; // count the output
echo $row_rs['FoodName']."&lt;br&gt;"; // print field and a line break
if (($counter % $break_point) == 0) { // if current row is equal to break_point
echo "&lt;/td&gt;&lt;td valign='top'&gt;"; // close cell and start a new column
}
} while ($row_rs = mysql_fetch_assoc($rs));
?&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;!-- body tags--&gt;
&lt;?php
mysql_free_result($rs);
?&gt;</font id=code></pre id=code>
Replied 26 Mar 2004 18:28:40
26 Mar 2004 18:28:40 Robert Kruse replied:
Now that's a Vertical Looper! I finally got a chance to test it out. Nice job!
Replied 09 Apr 2004 04:12:51
09 Apr 2004 04:12:51 webbie wm replied:
Replied 09 Apr 2004 18:33:36
09 Apr 2004 18:33:36 Mary Ann Walsh replied:
I use an extension from FelixOne called BiDimensional Repeat. I'm not as savvy as I'd like to be but this extension I can work. Check out his site:
www.felixone.it/extensions/dwextensionsen.asp?application=%25&environment=%25&Submit=Search&type=%3E%3D&offset=15
Of course you know this link should all be on one line. If it doesn't work, back out everything on the end up to "extensions"
Hope this helps. Oh, it is not a free extension.

Reply to this topic