SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What did I do wrong - tips please

    Code:
    <?php
    // This is where I get user info
    $query = 'SELECT id, username, iwins, ilosses, ipoints FROM punbb2_users';
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    		
    $line = mysql_fetch_array($result, MYSQL_ASSOC);
    ?>
    
    <dl>
         <dt>Player: </dt>
    	<dd><?php echo $line['username'] ?></dd>
    	<dt>Wins:</dt>
    	<dd><?php echo $line['iwins'] ?></dd>
    	<dt>Losses:</dt>
    	<dd><?php echo $line['ilosses'] ?></dd>
    	<dt>Points:</dt>
    	<dd><?php echo $line['ipoints'] ?></dd>
    	<dt>To Player:</dt>
    	<dd><a href="">Send Challenge</a><a href="">&nbsp;</a></dd>
    Okay so this is part of a custom profile I created for my users. To see an example go to this site. Click one of the usernames and it will take you to the page where the above code is used.

    Now the problem is that it is always using the same user to output no matter which user you click on. Why is this happening? How can I fix it?
    If you want more info leme know.

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to tell MySQL which user to select. Right now, since you have no WHERE clause in your SQL statement, you are selecting all users and then using the first row in that result set.

    PHP Code:
    $id = (int)$_GET['id'];
    $query "SELECT id, username, iwins, ilosses, ipoints FROM punbb2_users WHERE id=$id"
    Now to make the profile display the proper user, your link would need to look like:

    HTML Code:
    <a href="profile.php?id=1">Bob's Profile</a>
    Just put the user's ID as the value of that GET parameter and you're good to go.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your query statement you need to say something like:
    PHP Code:
     WHERE username '$Username' 
    (You are not choosing the user to select the info for)
    Kayzio - We don't hesitate, we accelerate.

  4. #4
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, thanks alot.

    I was thinking earlier of using a WHERE clause. I just didn't really know how to do it. I am kind of new to all this. The problem was defining the variable. This works now im stoked.
    thx again.


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
  •