Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Your Friends - Script

    I made this script, the idea was to showa user theyer friends.
    it successfully echos your number of friends.
    but the problem im having is , it only echos the first row.
    so its only showing your first friend, going by id.

    so it could say, you have six friends, yet only show you one.
    i cant figure it out.
    probally a stupid mistake.

    any ideas?

    thanks allot


    PHP Code:


    <?
    session_start
    ();
    include (
    'dbc.php');
    include (
    'functions.php');
    ?>

    <?php if (isset($_SESSION['user'])) { ?>
    <?
    $sql 
    'SELECT * FROM `friends`  WHERE `friend` = "'.$_SESSION['user'].'" ORDER BY id ASC LIMIT 15 ';
    $result mysql_query($sql) or die (mysql_error()); 
    $num mysql_num_rows($result);


    if (
    $num 0)
        {    
        echo 
    "You Currently have"$num," friends<br /><br /><br />";
        

    }
    else
    {
        echo 
    "You Currently Have No Friends.";
    }  

    ?>
        
        <?

    $sql 
    'SELECT * FROM `friends`  WHERE `friend` = "'.$_SESSION['user'].'" ORDER BY id ASC LIMIT 15 ';
    $result mysql_query($sql) or die (mysql_error()); 
    $num mysql_num_rows($result);
    $row mysql_fetch_array($result);
    $sql2 'SELECT * FROM `users`  WHERE `username` = "'.$row['befriended'].'" ORDER BY id ASC LIMIT 15 ';
    $result2 mysql_query($sql2) or die (mysql_error()); 
    $row2 mysql_fetch_array($result2);

        
    if (
    $num 0)
        {    
          echo 
    "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
        }

    ?> 


    <? ?>

  • #2
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    At the bottom of the script replace

    PHP Code:
    $row2 mysql_fetch_array($result2);

        
    if (
    $num 0)
        {    
          echo 
    "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
        } 
    with

    PHP Code:
    while ($row2 mysql_fetch_array($result2))
    {    
        echo 
    "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;

    It will cycle through all results from your second query

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    107
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by steelaz View Post
    At the bottom of the script replace

    PHP Code:
    $row2 mysql_fetch_array($result2);

        
    if (
    $num 0)
        {    
          echo 
    "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;
        } 
    with

    PHP Code:
    while ($row2 mysql_fetch_array($result2))
    {    
        echo 
    "<img src=\"",$row2['defaultpic']," \" width=\"85\" height=\"110\" />","<br />",$row['befriended'] ;

    It will cycle through all results from your second query

    steelaz , thanks allot !! i really apreaciate your help,
    at the minute im only really in the learning stages of php,

    but i looked up the while condition on php . net , and i now understand what it dose//means , so thanks allot , i really apreaciate it!.

    i do have another question though.

    the way ive done it now.

    is so it echos , the info in coloms, the problem is, when the page runs out, it carrys on going and dosent drop to a new line , is there any way of doing like
    after its shown 4, break to a new line/?


    thanks allot!
    Last edited by IamHe; 03-20-2009 at 01:10 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •