output data to mulitple columns with speedscript

jkrendal

New Member
Hi all,

I've been looking for a method to output data to a specified number of columns. I have found several PHP and ASP examples, but none employing speedscript. I've been working on converting the PHP example to speedscript, but Im not sure about employing arrays with progress. Having problems converting parts in red.

Anyone have an example of doing this?

this would output data vertically in columns like

aei
bfj
cgk
dhl

The PHP example


$columns = 4;

/* same as for each */
mysql_connect('localhost','',''
);
mysql_select_db('test'
);
$query = "SELECT stuff FROM mystuff ORDER BY stuff"
;
$result = mysql_query($query
);

/* set variable for total rows and columns */
$num_rows = mysql_num_rows($result
);

//we are going to set a new variables called $rows
$rows = ceil($num_rows / $columns
);

//to do this display, we will need to run another loop
//this loop will populate an array with all our values
while($row = mysql_fetch_array($result
)) {
$data[] = $row['stuff'
];
}

echo "<TABLE BORDER=\"0\">\n"
;

//here we changed the condition to $i < $rows
for($i = 0; $i < $rows; $i
++) {

echo "<TR>\n"
;

//here will run another loop for the amount of columns
for($j = 0; $j < $columns; $j
++) {
if(isset($data[$i + ($j * $rows
)])) {
echo "<TD>" . $data[$i + ($j * $rows)] . "</TD>\n"
;
}
}
echo "</TR>\n"
;
}
echo "</TABLE>\n"
;
?>

 

YET71

New Member
just an idea? maybe... u will need to play with the row setting value.. its not correct.

Code:
[font=Courier New][color=black]vcolumns = 4.[/color][/font][font=Courier New]
[/font]
[color=black]vx = 0.[/color]
[color=black]vrow = 1.[/color]
[font=Courier New][color=black][i]for each mystuff by stuff:[/i][/color][/font]
[font=Courier New][color=black][i]  vx = vx + 1.[/i][/color][/font]
[i][font=Courier New][color=black]  v[/color][/font][/i]
[font=Courier New][color=black][i]  if vx > vcolumns then do:[/i][/color][/font]
[font=Courier New][color=black][i]	assign vx = 1.  [/i][/color][/font]
[i][font=Courier New][color=black]	assign vrow = vrow + 1.[/color][/font][/i]
[color=black][font=Courier New][i]  end.
[/i][/font][font=Courier New]  vnumrows = vnumrows + 1.[/font][/color]
[font=Courier New][color=black]  create tmptblstuff.[/color][/font]
[font=Courier New][color=black]  assign tmptblstuff.column = vx [/color][/font]
[font=Courier New][color=black]		 tmptblestuff.row = vrow[/color][/font]
[font=Courier New][color=black]		 tmptblstuff.stuff = mystuff.stuff.[/color][/font]
[font=Courier New][color=black]   [/color][/font]
[font=Courier New][color=black]end.[/color][/font]
[font=Courier New][color=black]{&OUT} "<TABLE BORDER=\"0\">\n".[/color][/font][font=Courier New]

[/font][font=Courier New][color=black]repeat vx = 1 to vrow:
  {&OUT} "<TR>\n".[/color][/font][font=Courier New]
[color=black]  for each tmptblestuff where tmptblestuff.row = vx [/color][/font]
[color=black][font=Courier New]	by tmptblestuff.column ascending :
[/font][font=Courier New]	{&OUT} "<TD>" tmptblstuff.stuff "</TD>\n".[/font][/color]
[color=black][font=Courier New]  end.[/font]
[font=Courier New]  {&OUT} "</TR>\n".[/font]
[/color][color=black][font=Courier New]end.
{&OUT} "</TABLE>\n".[/font]
[font=Courier New] [/font][/color]
 
Top