36 users online (1 members and 35 guests)  


  Results 1 to 5 of 5

Related

  1. Replies: 2
  2. Displaying a table in Thunderbird    Forum: HTML Forum
    Replies: 1
  3. need help displaying results with links    Forum: PHP Forum
    Replies: 0
  4. PHP displaying search results    Forum: PHP Forum
    Replies: 24
  5. Replies: 4
  1. #1
    trix.1210's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2005
    Posts
    3

    Exclamation Displaying Paged Results In A Table

    Hi
    Im designing a website which shows types of furniture. The user can search and display results, like any shopping cart website, ebay is an example..
    I read some data from an external javascript datafile as in the example below. Each field is separated by a bar | character,
    I display the results on screen in an HTML table which works fine.
    furniture dbase.js:
    (ITEM, ,LOCATION, COLOUR, PRICE)
    "curtains | bedroom | red | 9.99"
    "table | kitchen | black | 12.99"
    "chair | lounge|green | 8.99"
    I want a google style paging navigation bar at the bottom of my search results on my page, so any results over 10 can be split onto several pages like the search engines do it.
    Ive scoured the web using copernic, google, dogpile and yahoo but cannot find any website or code example which has this code in javascript I can use.
    Im desperate!!
    any help appreciated!
    thanks!
    Matt

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Displaying Paged Results In A Table

    I'm only marginally proficient with javascript, but the main thing you have to do to create pages is use LIMIT on your SQL statement. For example:
    Code:
    SELECT * FROM tablename LIMIT 0,20
    The above example will give you the first 20 records from tablename. Then it's just a matter of putting HTML wrappers around the appropriate data elements.
    Hope this helps.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    trix.1210's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2005
    Posts
    3

    Re: Displaying Paged Results In A Table

    Quote Originally Posted by vinyl-junkie
    I'm only marginally proficient with javascript, but the main thing you have to do to create pages is use LIMIT on your SQL statement. For example:
    Code:
    SELECT * FROM tablename LIMIT 0,20
    The above example will give you the first 20 records from tablename. Then it's just a matter of putting HTML wrappers around the appropriate data elements.
    Hope this helps.
    Err.. my problem involves using HTML and JAVASCRIPT client-side. No other programming languages are involved...

  4. #4
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Displaying Paged Results In A Table

    Quote Originally Posted by trix.1210
    Err.. my problem involves using HTML and JAVASCRIPT client-side. No other programming languages are involved...
    Where are you getting your table data from? That will affect how you setup your paging.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  5. #5
    trix.1210's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2005
    Posts
    3

    Re: Displaying Paged Results In A Table

    My data is actually about records I own and held in a .js file as follows. There are 6 fields separated by a | bar character. I update the file by exporting from brilliantdatabase pro using its custom export feature. This gives me a file looking a bit like this:
    ____________________________________________________________________________________________________________
    (PRODUCT CODE, ARTIST, TITLE, LABEL, PRICE, GENRE)

    A("TV0001 |hughes & spier|idiot box|nice recs| 5.99 |HOUSE");
    A(" TV0002 | Awesome 3| Don’t Go | City Beat Records1992| 5.99 |HOUSE");
    A(" TV0003 | Baby doc & the dentist| Tales of the seraphim| | 5.99 |HOUSE");
    A(" TV0004 | Bump| I’m rushin| Fuel 42| 5.99 |HOUSE");
    A(" TV0005 | Cevin fisher| Music saved my life| Smile| 5.99 |HOUSE");
    A(" TV0006 | Cevin Fisher| The Freaks Come Out| | 5.99 |HOUSE");
    A(" TV0007 | Cls| Can You Feel It?| UMM| 5.99 |HOUSE");


    ____________________________________________________________________________________________________________
    the data is read in and stored in an array. using HTML/javascript. heres some of the code:

    // DISPLAY RESULTS TABLE COLUMN HEADINGS
    function writeResultTableHTML(dbobj, rows, sortby, target, tablestart)
    {

    var tablerows = 15;
    var tableend = "</tbody></TABLE>";
    var blankcoltxt;
    if (dbobj.blankcoltxt!=null)
    {
    blankcoltxt=dbobj.blankcoltxt;
    }
    else
    {
    blankcoltxt="N/A";
    }

    // Display all the Column headings for the table i.e. artist, title etc..
    tablestart+='<thead class="listCell" width=99% BORDER=1><br><br>';
    for (var j=0; j<dbobj.reportfields.length; j++)
    {
    var k = dbobj.reportfields[j];

    tablestart +=" <TH class=\"listCell\">"+dbobj.reclabels[k];
    //tablestart+='<tr class="listCell"> '+dbobj.reclabels[k]+' <\/th>';
    }
    //alert(tablestart);
    // add a buy button at the end of the table.
    tablestart+='<th class=\"listCell\" >buy<\TR></th>';
    // target.writeln("/thead");
    //


    // Sort Rows:
    var sorted;
    if (sortby=="null") sortby=null;
    if (rows.length<1) sortby=null;
    if (sortby!=null)
    {
    sorted=new Array(rows.length);
    if (sorted.sort!=null)
    {
    for (var i=0; i<rows.length; i++)
    {
    sorted[i]=rows[i][sortby]+"|"+i;
    // doesn't work (using separator instead):
    //sorted[i].index = i ;
    }
    // HACK: try to guess when we're sorting numbers.
    if (rows.length>0&& typeof (rows[rows.length-1][sortby])=="number"&& typeof (rows[0][sortby])=="number")
    {
    sorted.sort(numcmp);
    }
    else
    {
    sorted.sort();
    }
    }
    else
    {
    alert("Your web browser cannot sort these records - sorry!");
    sortby=null;
    }
    }
    // Output Rows:

    var irow;


    // write header table


    for (irow=0; irow<rows.length; irow++)
    //alert(irow);
    {
    var index;
    if (sortby!=null)
    {
    index=(stringSplit(sorted[irow], "|"))[1];
    }
    else
    {
    index=irow;
    }
    var dbrow = rows[index];
    // abb 6/25/97: putting href into the row objects now.
    var prefix = (dbrow.href==null) ? null : "<A href=\""+dbrow.href+"\">";
    var tail = "</A>";
    if ((irow%tablerows)==0)
    {

    target.writeln(tablestart);
    }
    target.write("<TR class=\"listCell\">");
    for (var j=0; j<dbobj.reportfields.length; j++)
    {
    var field = dbobj.reportfields[j];
    var options = dbobj.options[field];
    var val = dbrow[field];
    if (options==null)
    {
    // No options list, just print value.
    if (val==null||val==""||val==" ")
    {
    target.write("<TD class=\"listCell\"> N/A");
    }
    else
    {
    if (prefix==null)
    {
    target.write("<TD class=\"listCell\">"+val);
    }
    else
    {
    if (j==0&&val=="")
    {
    target.write("<TD class=\"listCell\">***");
    }
    else
    {
    target.write("<TD class=\"listCell\">"+prefix+val+tail);
    prefix=null;
    target.write("</UL>");
    }
    }
    }
    }
    if (j==0) var pc = val;
    if (j==1) var art = val;
    if (j==2) var titl = val;
    if (j==3) var labl = val;
    if (j==4) var pri = val;
    if (j==5) var genr = val;
    }

    }
    // Make sure we close the table up.
    if (((irow-1)%tablerows)!=(tablerows-1))
    {
    target.writeln(tableend+'</FORM><br>Done..');
    }
    outputStatus("Done.");
    }

    ____________________________________________________________________________________________________________
    Last edited by trix.1210; 11-06-2005 at 04:52 PM.



Tags for this Thread