SQL Searching: Return whole row of data

Discussion in 'MySQL' started by blackburn2413, Sep 11, 2010.

  1. #1
    Hello, have what may be a simple question for some of you. I have an sql query which searches a database for a name that is inputted with a html form. This is al working fine with the following query:

    $query = "SELECT *
    FROM `data`
    WHERE `name` LIKE CONVERT( _utf8 '$name'
    USING latin1 )
    COLLATE latin1_swedish_ci
    LIMIT 0 , 30 "; 
    PHP:
    This is returning the name from the database just fine, the problem is I am not getting it to display the rest of the values in that row. Is there any way to return everything as an array perhaps?
     
    blackburn2413, Sep 11, 2010 IP
  2. tewman

    tewman Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are several ways to get the array. Here is one example of what you can do:

    php code:
    
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
        printf ("ID: %s  Name: %s", $row[0], $row["name"]);
    }
    
    mysql_free_result($result);
    
    Code (markup):
    In the while loop, you can treat the results as an array. Either a numerical array or associated array..
     
    tewman, Sep 13, 2010 IP
  3. blackburn2413

    blackburn2413 Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Thanks, I forgot to use the code of $row[column name goes here] to display the other data. Got it working now. Thanks!
     
    blackburn2413, Sep 14, 2010 IP