Results 1 to 7 of 7

Thread: specific output from sql

  1. #1
    Join Date
    Feb 2009
    Posts
    156
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default specific output from sql

    hi, there are some record stored in a table and i want to retrieve some record , can i add serials numbers in front of every record?
    i.e there is a table
    index name designation
    ==============================
    1 tom clerk
    .
    .
    22 jeck clerk
    .
    .
    100 Harry clerk
    .
    .
    1001 Rohit clerk
    a table like this...
    ------------------------------------------------------------------


    i want out put like this

    1. tom clerk
    2. jeck clerk
    3. harry clerk
    4. rohit clerk


    means i want a serial no. with every record from database.....
    as 1,2,3,4 are the serial no. for every record , as its not stored in database... but i want to add it in out put...



    plz, if u can understand then plz reply...

  2. #2
    Join Date
    Jul 2007
    Location
    England
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Try this:

    PHP Code:
    $query="SELECT * FROM {$table};

    $result=mysql_query($query);

    $num=mysql_numrows($result);

    $i=0;

    echo'<ol>';

    while (
    $i < $num) {

    $var=mysql_result($result,$i,"field_name");

    echo'<li>
    $var</li>';

    }

    echo'</ol>'; 

  3. #3
    Join Date
    Feb 2009
    Posts
    156
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default

    hmm, but it will show he data in 1., 2., 3., 4., number only, but i want to assign these numbers to this data value only... means if i calls the data numbered 1, then the record belonging to 1 should be printed or called...


    means i not only want to print this data in this format only, but also want to use these values(1,2,3,4) in my programse whenever its required..

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The usual way to do this is to create two columns, one for the number and one for the name. You can use "auto increment" to make it do 1, 2, ..., x, for every name added.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Feb 2009
    Posts
    156
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default

    Quote Originally Posted by gurmeet View Post
    i.e there is a table
    index name designation
    ==============================
    1 tom clerk
    .
    .
    22 jeck clerk
    .
    .
    100 Harry clerk
    .
    .
    1001 Rohit clerk
    a table like this...
    ------------------------------------------------------------------


    i want out put like this

    1. tom clerk
    2. jeck clerk
    3. harry clerk
    4. rohit clerk


    means i want a serial no. with every record from database.....
    as 1,2,3,4 are the serial no. for every record , as its not stored in database... but i want to add it in out put...



    plz, if u can understand then plz reply...
    as described above, data is stored into database,
    but in output i want i need a index number,
    as harry is on 3rd number so 3 number is the index in output,
    in some situation it comes on 2nd number the index must b 2
    i think i need not to dscribe a column in database...

  6. #6
    Join Date
    Feb 2009
    Posts
    156
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default

    is there any expert who have chat ID where i can ask in detial n make him/her understand regarding my problem?

  7. #7
    Join Date
    Feb 2009
    Posts
    156
    Thanks
    0
    Thanked 4 Times in 3 Posts

    Default

    plz help me by giving ur suggestions ...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •