SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    display data from specific row

    Newbie question

    I have a table that contains two columns one is used as an identifier and the other is text I want to display.

    The question I have is do you have use an array to simply display the text of a single row like this

    $result = mysql_query('SELECT column_name FROM table WHERE id=1');
    while ($row = mysql_fetch_array($result)) {
    echo $row['column_name'];
    }

    Is there a simplier way or is using the array the only way, I just find it funny to set up an array like this with only a single item in it.

    Thanks

  2. #2
    SitePoint Guru
    Join Date
    Jul 2004
    Location
    Raleigh, NC
    Posts
    783
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Crimin
    Newbie question

    I have a table that contains two columns one is used as an identifier and the other is text I want to display.

    The question I have is do you have use an array to simply display the text of a single row like this

    $result = mysql_query('SELECT column_name FROM table WHERE id=1');
    while ($row = mysql_fetch_array($result)) {
    echo $row['column_name'];
    }

    Is there a simplier way or is using the array the only way, I just find it funny to set up an array like this with only a single item in it.

    Thanks
    this returns only the first result:
    PHP Code:
    echo mysql_result($result0); 
    also, if you did want to use your method - if there's only 1 possible item returned, a loop is not necessary:
    PHP Code:
    $row mysql_fetch_array($result);
    echo 
    $row['column_name']; 


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
  •