SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2001
    Location
    Holland
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A !very simple question..

    ! not as in reverse

    But, my question: I like to fetch someones username out of the database by info out of another column. This ain't so hard.. but I wish to fetch it as an variable!!

    Not it's a single row, I tryed the mysql_fetch_row but I think my problem isn't sql but php related.

    I've managed to fetch the name but my code was way to messy.. I don't even dare to post it here

    (/me is ashamed)

  2. #2
    SitePoint Enthusiast alnixon's Avatar
    Join Date
    May 2001
    Location
    Preston (UK)
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
        $sql mysql_query(" SELECT UserName ".
        
    " FROM Table ".
        
    " WHERE ID = '$id'");
        
        if (!
    $sql) {  
            echo(
    "<P>Error retrieving username from database!<BR>".       
            
    "Error: " mysql_error());  
            exit();
        }
        
        while (
    $temp mysql_fetch_array($sql)) {  
            
    $username $temp["UserName"];  
        } 
    I think this is what you mean. Sorry if I've got the wrong end of the stick.

  3. #3
    SitePoint Member
    Join Date
    May 2001
    Location
    Holland
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it works, thank you kindly..

    Just one but, doens't the array fetch more then one rows? Shouldn't I use row instead..

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just as a side note,

    PHP Code:
    $sql mysql_query(" SELECT UserName ".
        
    " FROM Table ".
        
    " WHERE ID = '$id'"); 
    Can be written much cleaner, note you don't need to concatenate the query lines together, PHP ignores whitespace like that.
    PHP Code:
    $sql mysql_query("SELECT UserName 
                        FROM Table 
                         WHERE ID = '
    $id'"); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast alnixon's Avatar
    Join Date
    May 2001
    Location
    Preston (UK)
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh - I know that now freddydoesphp - I just copied and pasted from the first script I ever did - I then went on to design an entire database management system like that. then I decided to make it xhtml complient and had to replace all of my ' with \" as I hadn't learnt that and while looking at the doc for echo I saw that php ignores whitespace (I then kicked myself!)

    joop - the best way to learn is to experiment - try things out, read the docs and see what you can do.
    Da Big Cheese
    --------------
    I'm not entirely sure on this, but ....
    [insert my post here]


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
  •