seeking suggestion for posting spreadsheet data on web

Discussion in 'HTML' started by Ross, Aug 22, 2005.

  1. Ross

    Ross Guest

    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.
     
    Ross, Aug 22, 2005
    #1
    1. Advertising

  2. Ross

    Neredbojias Guest

    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.

    --
    Neredbojias
    Contrary to popular belief, it is believable.
     
    Neredbojias, Aug 22, 2005
    #2
    1. Advertising

  3. Ross

    Ross Guest

    "Neredbojias" <> wrote in message
    news:...
    >
    > 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.
     
    Ross, Aug 22, 2005
    #3
  4. Ross

    max Guest

    On Mon, 22 Aug 2005 16:25:29 +0800, "Ross" <> wrote:

    >
    >"Neredbojias" <> wrote in message
    >news:...
    >>
    >> 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.
    >

    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.
     
    max, Aug 22, 2005
    #4
  5. Ross

    Rincewind Guest

    On Mon, 22 Aug 2005 10:23:07 GMT, max wrote:

    > On Mon, 22 Aug 2005 16:25:29 +0800, "Ross" <> wrote:
    >
    > >
    > >"Neredbojias" <> wrote in message
    > >news:...
    > >>
    > >> 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.
    > >


    Check out the PHP site www.php.net for multi dimensional arrays and for
    createing arrays with spreadsheet output.
     
    Rincewind, Aug 22, 2005
    #5
  6. Ross

    william Guest

    On Mon, 22 Aug 2005 11:20:01 +0800, Ross wrote:

    > 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.
     
    william, Aug 22, 2005
    #6
  7. On Monday 22 August 2005 04:20, Ross wrote:

    > 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

    --
    Roy S. Schestowitz Useless fact: Florida is bigger than England
    http://Schestowitz.com
     
    Roy Schestowitz, Aug 22, 2005
    #7
  8. Ross

    Ross Guest

    "william" <> wrote in message
    news:39iv2tv2jz8h.1dhbcedlvgxop$...
    > On Mon, 22 Aug 2005 11:20:01 +0800, Ross wrote:
    >
    >> 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'))
    );
     
    Ross, Aug 22, 2005
    #8
  9. Ross

    Toby Inkster Guest

    Ross wrote:

    > 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

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Aug 22, 2005
    #9
  10. Ross

    william Guest

    On Mon, 22 Aug 2005 23:37:26 +0800, Ross wrote:

    > "william" <> wrote in message
    > news:39iv2tv2jz8h.1dhbcedlvgxop$...
    >> On Mon, 22 Aug 2005 11:20:01 +0800, Ross wrote:
    >>
    >>> 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.
     
    william, Aug 22, 2005
    #10
  11. Ross

    Ross Guest

    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".
     
    Ross, Aug 24, 2005
    #11
  12. Ross

    Toby Inkster Guest

    Ross wrote:

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

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Aug 24, 2005
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. alanb
    Replies:
    2
    Views:
    554
    alanb
    Apr 23, 2004
  2. Nice Chap

    Seeking Suggestion

    Nice Chap, Apr 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    293
    Cowboy \(Gregory A. Beamer\)
    Apr 27, 2004
  3. Roger Twomey
    Replies:
    1
    Views:
    12,639
    Roger Twomey
    Apr 27, 2004
  4. Roberto Lopes
    Replies:
    1
    Views:
    2,208
    mahere
    Dec 27, 2007
  5. AmitKu
    Replies:
    7
    Views:
    546
    John Timney \(MVP\)
    Jan 8, 2007
Loading...

Share This Page