how return a field name with the value in a mysql query?

Discussion in 'PHP' started by srdva59, Feb 15, 2009.

  1. #1
    --------------------------------------------------------------------------------

    hi,
    i need get the name of the field by a query
    for example

    if a do this:

    $res = mysql_query( "select * from total )
    $v1=mysql_fetch_row_name($res);
    while($v1=mysql_fetch_row($res)) {

    echo $v1[0]; // return the value of field number 0

    }

    but i need to know also this:


    echo "the field name xxx have this record ". $v1[0];

    in vb we have the objects that return the name and the value and all information of the field but how can i see this in php?
    thanks a lot for your help
     
    srdva59, Feb 15, 2009 IP
  2. Scripten

    Scripten Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Lol ur code is totally wrong...

    I'll give an example with my favourite table "users" :D

    
    <?php
    $select = mysql_query("SELECT * FROM users");
    while($row = mysql_fetch_array($select)) {
     echo $row['username']; //This will display the username selected from the query
    }
    ?>
    
    PHP:
    You can change 'username' to ip, last_login, etc.
     
    Scripten, Feb 15, 2009 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    ads2help, Feb 15, 2009 IP