seeking suggestion for posting spreadsheet data on web

R

Ross

dear all, i have the following table of data to post on web,

name size length 0min 3min 10min chart
A 3 5 1 10 3 figA.gif
B 5 2 2 4 3 figB.gif
C 4 3 3 9 6 figC.gif
....

I am seeking your advice on the programming language for such an action. i
prefer a web table capable of sorting by size, length and so on, therefore
built-in function for sorting is appreciated.
 
N

Neredbojias

With neither quill nor qualm, Ross quothed:
dear all, i have the following table of data to post on web,

name size length 0min 3min 10min chart
A 3 5 1 10 3 figA.gif
B 5 2 2 4 3 figB.gif
C 4 3 3 9 6 figC.gif
...

I am seeking your advice on the programming language for such an action. i
prefer a web table capable of sorting by size, length and so on, therefore
built-in function for sorting is appreciated.

Html per se has no functions for such programming. I'd suggest some
server-side scripting, such as PHP.
 
R

Ross

Neredbojias said:
Html per se has no functions for such programming. I'd suggest some
server-side scripting, such as PHP.
What keyword would you suggest me to have a look at PHP to see whether it is
really suitable before going deep in coding? thx for your response.
 
M

max

What keyword would you suggest me to have a look at PHP to see whether it is
really suitable before going deep in coding? thx for your response.
Some of the more knowledgeable of the 7th Cavalry(!) may arrive shortly, but
until they do, try sticking
spreadsheet site:www.php.net
and
spreadsheet php
and
spreadsheet php.net
into google
If nothing else, some of the info there may help you decide which blind
alleys to avoid.
 
W

william

dear all, i have the following table of data to post on web,

name size length 0min 3min 10min chart
A 3 5 1 10 3 figA.gif
B 5 2 2 4 3 figB.gif
C 4 3 3 9 6 figC.gif
...

I am seeking your advice on the programming language for such an action. i
prefer a web table capable of sorting by size, length and so on, therefore
built-in function for sorting is appreciated

php is your best bet

<?php
/* this is where the array values are assigned*/
$table_data= array(array ( 'a', 3, 5, 1, 10, 3, 'figA.gif' ),
(array ( 'b', 5, 2, 2, 4, 3, 'figB.gif' )),
(array ( 'c', 4, 3, 3, 9, 6, 'figC.gif'
))
);
/* This is where you describe the funtion "compare". The number in the
square bracket corresponds with the column in the array, remember PHP
starts counting at 0, so [1] is the second column or in your example "size"
*/
function compare($x, $y )
{
if($x[1] == $y[1] )
return 0;
else if ($x[1] < $y[1])
return -1;
else return 1;
}

/* This is where the sorting takes place */
usort($table_data, 'compare');

/* This is where the results are output to the web page */
for ( $row = 0; $row <3; $row++)
{
while ( list ( $key, $value ) = each( $table_data[$row]))
{
echo "\t $value";
}
echo '<br>';
}
?>
This should work for you. But you'll need to work out how to get the data
in from a spread sheet or file.
 
R

Roy Schestowitz

dear all, i have the following table of data to post on web,

name size length 0min 3min 10min chart
A 3 5 1 10 3 figA.gif
B 5 2 2 4 3 figB.gif
C 4 3 3 9 6 figC.gif
...

I am seeking your advice on the programming language for such an action. i
prefer a web table capable of sorting by size, length and so on, therefore
built-in function for sorting is appreciated.

Hi Ross,

I always prefer to think in terms of comma-separated values when handling
spreadsheets. Let us say that you use PHP and then pick one token at a time
with the intention of feeding it in to the database.

Thereafter, all you ought to do is create a database with tuples that
correspond to the columns of the table above. You should create some
meaningful functions (abstraction) to fetch column (value) given field
(row) and then work deeper to get more complex operations working. There
must be something like this lying around publicly, so don't re-invent the
wheel if possible. Do your homework before implementing anything.

To output the data, it would sensible in this particular case to place
everything in tables (Look ma! No divs!), e.g.

<table>
<tbody>
<tr>
<td>
A
</td>
<td>
3
</td>
<td>
6
</td>
<td>
1
</td>
<td>
10
</td>
<td>
3
</td>
<td>
<img src="figA.gif" alt="figA" />
</td>
</tr>
</tbody>
</table>


Hope it helps,

Roy
 
R

Ross

william said:
dear all, i have the following table of data to post on web,

name size length 0min 3min 10min chart
A 3 5 1 10 3 figA.gif
B 5 2 2 4 3 figB.gif
C 4 3 3 9 6 figC.gif
...

I am seeking your advice on the programming language for such an action.
i
prefer a web table capable of sorting by size, length and so on,
therefore
built-in function for sorting is appreciated

php is your best bet

<?php
/* this is where the array values are assigned*/
$table_data= array(array ( 'a', 3, 5, 1, 10, 3, 'figA.gif' ),
(array ( 'b', 5, 2, 2, 4, 3, 'figB.gif' )),
(array ( 'c', 4, 3, 3, 9, 6, 'figC.gif'
))
);
/* This is where you describe the funtion "compare". The number in the
square bracket corresponds with the column in the array, remember PHP
starts counting at 0, so [1] is the second column or in your example
"size"
*/
function compare($x, $y )
{
if($x[1] == $y[1] )
return 0;
else if ($x[1] < $y[1])
return -1;
else return 1;
}

/* This is where the sorting takes place */
usort($table_data, 'compare');

/* This is where the results are output to the web page */
for ( $row = 0; $row <3; $row++)
{
while ( list ( $key, $value ) = each( $table_data[$row]))
{
echo "\t $value";
}
echo '<br>';
}
?>
This should work for you. But you'll need to work out how to get the data
in from a spread sheet or file.

Wow! u've almost done all the things, thx!! BTW, how to tell PHP which key
is to be used in the 'compare' function? and to facilitate automation, can
PHP interpret the following instead (add something like '\' to let it know
it's unfinished yet?) ?

$table_data= array(
(array ( 'a', 3, 5, 1, 10, 3, 'figA.gif' ))
,
(array ( 'b', 5, 2, 2, 4, 3, 'figB.gif' ))
,
(array ( 'c', 4, 3, 3, 9, 6, 'figC.gif'))
);
 
T

Toby Inkster

Ross said:
I am seeking your advice on the programming language for such an action. i
prefer a web table capable of sorting by size, length and so on, therefore
built-in function for sorting is appreciated.

Down below are a couple of nice PHP functions that may be of use. I've
taken them from my CMS at work and munged them a little to make them
independent of it. I've not tested these munged ones, so they may need a
little adjusting.

Below the PHP code are some instructions on how they should be used.

<?php
function insert_datatable_cmp ($a, $b) {
return ($a[$_GET['sort']]<$b[$_GET['sort']]) ? -1 : 1;
}

function insert_datatable ($data, $headings, $options=array(), $caption='') {

if ($caption!='' && $options['h2']==1) print "<h2>$caption</h2>\n";
print "<table>\n";
if ($caption!='' && $options['h2']!=1) print "<caption>$caption</caption>\n";
print "<thead><tr>";
$i = 0;
foreach ($headings as $h) {
print "<th scope=\"col\"><a href=\"${_SERVER['PHP_SELF']}?sort=$i\">$h</a></th>";
$i++;
}
print "</tr></thead>\n<tbody>\n";

$lines = explode("\n",$data);
$i = 0;
while ($l = array_shift($lines)) {
$s[$i++] = explode("|",$l);
}

if(isset($_GET['sort'])) {
usort($s,"insert_datatable_cmp");
}

foreach ($s as $S) {
print "<tr>";
for($i=0;$S[$i];$i++)
{
if ($options['email:'.$i]==1)
{
$S[$i] = '<a href="mailto:' . $S[$i] . '">' . $S[$i] . '</a>';
} elseif ($options['web:'.$i]==1)
{
$S[$i] = '<a href="' . $S[$i] . '">' . $S[$i] . '</a>';
}

if ($options['join:'.$i.':'.($i+1)]==1)
{
print '<td colspan="2">' . $S[$i] . ' ' . $S[$i+1] . '</td>';
$i++;
}
else
{
print '<td>' . $S[$i] . '</td>';
}
}
print "</tr>\n";
}

print "</tbody></table>\n";

}
?>

To create the table you posted, you would do this:

<?php
$d = "A|3|5|1|10|3|figA.gif
B|5|2|2|4|3|figB.gif
C|4|3|3|9|6|figC.gif";

$h = array('name','size','length','0min','3min','10min','chart');
$o = array('web:6'=>1);
$c = 'My Caption';

insert_datatable($d, $h, $o, $c);
?>

As you can see, the first argument for the insert_datatable() function is
a pipe-seperated table of data. The second argument is a PHP array of
headings. The third argument is an array of "options" (explained later).
The last argument is a caption for the table. The first two arguments are
required. The last two are optional. (But if you include a caption, you
must also include the options array!)

The options are set like this:
$o = array('option1'=>1, 'option2'=>1, 'option3'=>1);
so that the "=>1" means "switch this option on".

What options can be used? "web:X" means that column number X is a web
link. "email:X" means that column X is an e-mail address. "join:X:Y" means
that columns X and Y should be joined (useful if X is a person's first
name and Y is their surname!). Column numbers start from 0, not 1.

That's about it!

Copyright: 2005 Toby Inkster. You may use the above in your own projects,
under the terms of the GNU GPL. http://www.gnu.org/copyleft/gpl.html
 
W

william

william said:
dear all, i have the following table of data to post on web,

name size length 0min 3min 10min chart
A 3 5 1 10 3 figA.gif
B 5 2 2 4 3 figB.gif
C 4 3 3 9 6 figC.gif
...

I am seeking your advice on the programming language for such an action.
i
prefer a web table capable of sorting by size, length and so on,
therefore
built-in function for sorting is appreciated

php is your best bet

<?php
/* this is where the array values are assigned*/
$table_data= array(array ( 'a', 3, 5, 1, 10, 3, 'figA.gif' ),
(array ( 'b', 5, 2, 2, 4, 3, 'figB.gif' )),
(array ( 'c', 4, 3, 3, 9, 6, 'figC.gif'
))
);
/* This is where you describe the funtion "compare". The number in the
square bracket corresponds with the column in the array, remember PHP
starts counting at 0, so [1] is the second column or in your example
"size"
*/
function compare($x, $y )
{
if($x[1] == $y[1] )
return 0;
else if ($x[1] < $y[1])
return -1;
else return 1;
}

/* This is where the sorting takes place */
usort($table_data, 'compare');

/* This is where the results are output to the web page */
for ( $row = 0; $row <3; $row++)
{
while ( list ( $key, $value ) = each( $table_data[$row]))
{
echo "\t $value";
}
echo '<br>';
}
?>
This should work for you. But you'll need to work out how to get the data
in from a spread sheet or file.

Wow! u've almost done all the things, thx!! BTW, how to tell PHP which key
is to be used in the 'compare' function?

this is just one way of doing it, what you need to do is create a form to
enter which column to sort by, if you look at the compare function you'll
see I've already said which part to change to sort by a different row. so
what you have to work out is how to replace the number betweem the square
brackets with a string that you pass through the form.
and to facilitate automation, can
PHP interpret the following instead (add something like '\' to let it know
it's unfinished yet?) ?

I presume you mean the entereng of data? if so then you need to look at the
php manual for inserting spreadsheet data as arrays.
 
R

Ross

How to disable sorting by, say, length and chart ? I find the order is
important to
display so cannot just single them out from "array".
 
T

Toby Inkster

Ross said:
How to disable sorting by, say, length and chart ? I find the order is
important to display so cannot just single them out from "array".

Slight improvement to my original function. Adds the ability to suppress
sorting for certain columns.

<?php
function insert_datatable_cmp ($a, $b) {
return ($a[$_GET['sort']]<$b[$_GET['sort']]) ? -1 : 1;
}

function insert_datatable ($data, $headings, $options=array(), $caption='') {

if ($caption!='' && $options['h2']==1) print "<h2>$caption</h2>\n";
print "<table>\n";
if ($caption!='' && $options['h2']!=1) print "<caption>$caption</caption>\n";
print "<thead><tr>";
$i = 0;
foreach ($headings as $h) {
if ($options["nosort:$i"]==1) {
print "<th scope=\"col\">$h</th>";
} else {
print "<th scope=\"col\"><a href=\"${_SERVER['PHP_SELF']}?sort=$i\">$h</a></th>";
}
$i++;
}
print "</tr></thead>\n<tbody>\n";

$lines = explode("\n",$data);
$i = 0;
while ($l = array_shift($lines)) {
$s[$i++] = explode("|",$l);
}
if(isset($_GET['sort'])) {
usort($s,"insert_datatable_cmp");
}
foreach ($s as $S) {
print "<tr>";
for($i=0;$S[$i];$i++)
{
if ($options['email:'.$i]==1)
{
$S[$i] = '<a href="mailto:' . $S[$i] . '">' . $S[$i] . '</a>';
} elseif ($options['web:'.$i]==1)
{
$S[$i] = '<a href="' . $S[$i] . '">' . $S[$i] . '</a>';
}

if ($options['join:'.$i.':'.($i+1)]==1)
{
print '<td colspan="2">' . $S[$i] . ' ' . $S[$i+1] . '</td>';
$i++;
}
else
{
print '<td>' . $S[$i] . '</td>';
}
}
print "</tr>\n";
}

print "</tbody></table>\n";

}

$d = "A|3|5|1|10|3|figA.gif
B|5|2|2|4|3|figB.gif
C|4|3|3|9|6|figC.gif";

$h = array('name','size','length','0min','3min','10min','chart');
$o = array('web:6'=>1, 'nosort:2'=>1, 'nosort:6'=>1);
$c = 'My Caption';

insert_datatable($d, $h, $o, $c);
?>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top