<?php
//basic mysql connection, you'd want to use a DB class or something
$connect = @mysql_connect("localhost","username","password") or die("Could not connect to server.");
$db = @mysql_select_db("database") or die(mysql_error());
$query = "SELECT * FROM table";
$result = @mysql_query($query) or die("Could not execute query");
$check = mysql_num_rows($result);
if ($check == 0) {
echo "Table is empty.";
} else {
?>
<table>
<?php
$i = 1;
while ($row = mysql_fetch_array($result)) {
if ($i == 1) {
?>
<tr>
<?php
}
?>
<td><?php echo $row['column']; ?></td>
<?php
if ($i == 7) { /* here we have 7 columns per row, if you want 10 columns just change this value to 10 instead of 7 */
$i = 0;
?>
</tr>
<?php
}
$i++;
}
?>
</tr>
</table>
<?php
}
?>
# this will relay calls to multiple objects
#
# objects will be removed from the multiplexer when
# a call to them results in an exception
#
# I use it to multiplex input streams (see example below class)
class Multiplexer
def initialize(*args)
@streams = args
end
def method_missing(m, *args)
result = nil
while(t = @streams.shift)
begin
if(result = t.send(m,*args))
@streams.push(t)
return result
end
rescue
end
end
end
end
require 'open3'
Open3.popen3("ruby -e '$stderr.puts(\"foo\"); $stdout.puts(\"bar\"); $stderr.puts(\"baz\");'") do |input,output,error|
expected = ['foo','bar','baz']
input.close
f=Multiplexer.new(error,output)
while(line=f.gets)
if((e=expected.shift) != line.chomp) then
puts "ERROR: failed unit test; expected #{e}, got #{line.chomp}"
end
puts line
end
end