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";
?>
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";
?>