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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying to show buddies in profile page

    Hi,
    I have a site that allows profiles etc.
    I want to take a function off of one page and add it to another. Sounds easy enough? I now have it set so the person logged in can add buddies but only that person can view them. Now, I want everyone to be able to see each others buddies from the persons profile page.

    Here is the profile pages SQLs and function
    PHP Code:
    function show_profile($user_id)
    {
        global 
    $tb_users$tb_comments$tb_sessions$tb_user_types;
        global 
    $base_url$tpl;

        
    $i=$user_id;
        
    $rate_sql "
        select
            $tb_users.id as id,
            $tb_users.username as user_name,
            $tb_users.realname as realname,
            $tb_users.description as description,
            $tb_users.video as video,
            $tb_users.age as age,
            $tb_users.user_type as user_type,
            $tb_users.state as state,
            $tb_users.country as country,
            $tb_users.url as url,
            $tb_users.quote as quote,
            $tb_users.average_rating as average_rating,
            $tb_users.total_points as total_points,
            $tb_users.total_ratings as total_ratings,
            $tb_users.last_logged as last_logged,
            $tb_users.user_type as usertype,
            $tb_users.email as useremail
        from
            $tb_users
        where
            id = '$user_id' "
    ;

    $rate_query mysql_query($rate_sql) or die(mysql_error());

    if(
    mysql_num_rows($rate_query) > 0)
    {
        while(
    $array mysql_fetch_array($rate_query))
        {

                
    $image_src get_image($array["id"]);

                
    $qry "select now() from $tb_users";
                
    $resmysql_query($qry);
                
    $result mysql_fetch_row($res) or die(mysql_error());

                
    $now $result[0];

                
    $then $array[last_logged];
                
    $then1=$array[last_logged];

                
    //--------------------------

                
    $now strtotime ("$now");
                
    $then strtotime ("$then");
                
    $difference $now $then ;
                
    $num $difference/86400;
                
    $days intval($num);
                
    $num2 = ($num $days)*24;
                
    $hours intval($num2);
                
    $num3 = ($num2 $hours)*60;
                
    $mins intval($num3);
                
    $num4 = ($num3 $mins)*60;
                
    $secs intval($num4);

                
    // $temp = split(" ",$array['last_logged']);
                // $temp1 = split("-",$temp[0]);
                // $temp2 = split(":",$temp[1]);
                // $array[last_logged] = $temp1[1]."-".$temp1[2]."-".$temp1[0]." ".$temp2[0].":".$temp2[1].":".$temp2[2];
                

                
    if ($then1 == "0000-00-00 00:00:00")
                    
    $last_logged_text="";
                else
                    
    $last_logged_text="$days days $hours hours and $mins mins ago";

                
    $link_field_size strlen($base_url "/?i=" $user_id);
                
    $favouritelink "<td align='right'><a href=\"$base_url/add_to_favourites.php?i=$i\"><img align=\"top\" border=\"0\" src=\"$base_url/images/addfavourite.jpg\" alt=\"Add to Favourites\" title=\"Add to Favourites\"></a>&nbsp;</td>";
                
    $favouritelink1 "<td >&nbsp;</td>";

                
    $favouritelink = isset($_SESSION['userid']) ? $favouritelink $favouritelink1;
     
                
    $short_entry eregi_replace(".gif"""$array["country"]);
                
    $country eregi_replace("_"" "$short_entry);
                
    $desc1 = array();
                
    $desc2 = array();

                
    $desc1 split(" ",$array[description]);

                
    $tot_desc count($desc1);
                
    $mylength 0;
                
    $index 0;
                for(
    $i=0;$i<$tot_desc;$i++)
                {
                    
    $length strlen($desc1[$i]);
                    if ((
    $mylength $length)>80)
                    {
                        
    $req_len 50 $mylength;
                        
    $desc2[$index] = substr($desc1[$i],0,$req_len);
                        
    $desc1[$i] = substr($desc1[$i],$req_len);
                        
    $mylength strlen($desc1[$i]);
                        
    $index++;
                    }
                    if (
    $mylength 80)      {    $desc2 mysplit($desc1[$i],$desc2);             }
                    else
                    {
                        
    $mylength += strlen($desc1[$i]);
                        
    $desc2[$index] = $desc1[$i];
                        
    $index++;
                    }
                }
                
    $array[description] = implode(" ",$desc2);
                
    $array[description]=nl2br($array[description]);

                
    $title "About";
                
    $extra_photos get_image($array["id"], 2);

                if (
    strpos($extra_photos,"notfound_image"))
                    
    $extra_photos="";           

                
    $users "";
                
                
    $gu_sql "select data from $tb_sessions";
                
    $gu_query mysql_query($gu_sql) or die(mysql_error());
                
    $total_user_sessions mysql_num_rows($gu_query);
                if(
    $total_user_sessions)
                {
                    
    $username_array = array();
                    
    $userid_array = array();
                    while(
    $gu_array mysql_fetch_array($gu_query))
                    {
                        if(
    strlen(trim($gu_array["data"])))
                        {
                            
    $strings split(";"$gu_array["data"]);
                            for(
    $x 0$x sizeof($strings); $x++)
                            {
                                if(
    strlen($strings[$x]))
                                {
                                    if((
    eregi("^username"$strings[$x])) ||(eregi("^}username"$strings[$x])))
                                    {
                                        
    $parts split(":"$strings[$x]);
                                        
    $username_array[] = eregi_replace("\""""$parts[2]);
                                    }
                                }
                            }
                        }
                    }  

                    
    $status="<img align=\"absmiddle\" src=\"$base_url/images/user_offline.gif\" hspace=\"3\" vspace=\"1\" alt=\"Offline\" title=\"Offline\">";
                        
    $user_status="Offline";
                    if(
    sizeof($username_array))
                    {
                        
    $un array_unique($username_array);
                        for(
    $z 0$z sizeof($un); $z++)
                        {
                            if(
    $un[$z] == $array[user_name]) 
                            {
                                
    $status="<img src=\"$base_url/images/user_online.gif\" hspace=\"3\" vspace=\"1\" alt=\"Online\" title=\"Online\" align=\"absmiddle\">";
                                                 
    $user_status="Online";
                                break;
                            }
                        }
                    }


                } 
    // if 


                
    $usql "
                    select
                        user_type
                    from
                        $tb_user_types
                    where id=$array[usertype] "
    ;
        
                
    $ures=mysql_query($usql);
                
    $urs mysql_fetch_array($ures);
                
    $user_types=$urs[0];
                
                
    $uid=$user_id;
                
    $uid=$user_id;
                
    $site_url $array['url'];
                
    $site_url str_replace("http://","",$site_url);
                
    $site_url str_replace("HTTP://","",$site_url);
                
    $site_url "http://" "$site_url" ;     
                
    $tpl->assign(array('EXTRA_PHOTOS' => !empty($extra_photos) ? table('Extra Images'$extra_photos) : '',
                                   
    'STATUS' => $status,
                                   
    'USER_STATUS' => $user_status,
                                   
    'FAVOURITELINK' => $favouritelink,
                                   
    'AVERAGE_RATING' => $array['average_rating'],
                                   
    'TOTAL_POINTS' => $array['total_points'],
                                   
    'TOTAL_RATINGS' => $array['total_ratings'],
                                   
    'USER_NAME' => $array['user_name'],
                                   
    'REAL_NAME' => $array['realname'],
                                   
    'AGE' => $array['age'],
                                   
    'DESCRIPTION' => $array['description'],
                                   
    'VIDEO' => $array['video'],
                                   
    'STATE' => $array['state'],
                                   
    'COUNTRY' => '<img align="top" border="1" src="' $base_url '/images/flags/' $array['country'] . '" hspace="5" alt="' $country '" title=" ' $country '">' $country,
                                   
    'URL' => '<a class=link01 href="' $site_url '" target="_blank">' $site_url '</a>',
                                   
    'QUOTE' => '<i>&quot;' $array['quote'] . '&quot;</i>',
                                   
    'LAST_LOGGED_TEXT' => $last_logged_text,
                                   
    'UID' => $uid,
                                   
    'ADDITIONAL_FIELDS' => view_additional_fields($uid)));
                
    $tpl->parse('SHOW_PROFILE_CONTENT''show_profile');
                
                
    $content $tpl->fetch('SHOW_PROFILE_CONTENT');
                
                
    $final_output $content;
                
    //$final_output .= table('<img src="images/description.gif">', $content);
        
            //  $content = "";
        
    }// while
        
    }
    return 
    $final_output;


    Here is the function I want to add but want everyone to be able to see it
    PHP Code:
    <?php
    include("./admin/config.php");
    include(
    "$include_path/common.php");
    include(
    "$include_path/pm_check.php");

    global 
    $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SESSION_VARS;

    global 
    $_SESSION;

    if (
    $HTTP_POST_VARS!="")
        
    $_POST=$HTTP_POST_VARS;

    if (
    $HTTP_GET_VARS!="")
        
    $_GET=$HTTP_GET_VARS;

    if (
    $HTTP_SESSION_VARS!="")
        
    $_SESSION=$HTTP_SESSION_VARS;


    check_user_login();

    include(
    "$include_path/$table_file");
    include(
    "$include_path/doc_head.php");
    include(
    "$include_path/styles.php");




    include(
    "$include_path/left.php");
    include (
    "Ads_new.php");
    include(
    "$include_path/right.php");


    $fav_id = isset($_GET['fid']) ? $_GET['fid'] : 0;
    $profile_id = isset($_GET['pid']) ? $_GET['pid'] : 0;
    $user_id $_SESSION['userid'];

    if(
    $fav_id != 0){
      
    $sql="delete from $tb_favourites where user_id='$user_id' and fav_user_id='$fav_id'";
      
    mysql_query($sql) or die(mysql_error());
    }

    $profile_content "";
    if(
    $profile_id != 0){
       
    $rate_sql "
        select
            $tb_users.id as id,
            $tb_users.username as user_name,
            $tb_users.realname as realname,
            $tb_users.description as description,
            $tb_users.age as age,
            $tb_users.user_type as user_type,
            $tb_users.state as state,
            $tb_users.country as country,
            $tb_users.url as url,
            $tb_users.quote as quote,
            $tb_users.average_rating as average_rating,
            $tb_users.total_points as total_points,
            $tb_users.total_ratings as total_ratings,
            $tb_users.last_logged as last_logged,
            $tb_users.user_type as usertype,
            $tb_users.email as useremail
        from
            $tb_users
        where
            id = '$profile_id'"
    ;

       
    $rate_query mysql_query($rate_sql) or die(mysql_error());
       
    $array mysql_fetch_array($rate_query);
       
    $qry "select now() from $tb_users";
       
    $resmysql_query($qry);
       
    $result mysql_fetch_row($res) or die(mysql_error()); 
       
    $now $result[0];

       
    $then $array[last_logged];

    //--------------------------

    $now strtotime ("$now");
    $then strtotime ("$then");
    $difference $now $then ;
    $num $difference/86400;
    $days intval($num);
    $num2 = ($num $days)*24;
    $hours intval($num2);
    $num3 = ($num2 $hours)*60;
    $mins intval($num3);
    $num4 = ($num3 $mins)*60;
    $secs intval($num4);

    $short_entry eregi_replace(".gif"""$array["country"]);
    $country eregi_replace("_"" "$short_entry);
    $extra_photos get_image($array["id"], 2);
    $users "";
    $gu_sql "select data from $tb_sessions";
    $gu_query mysql_query($gu_sql) or die(mysql_error());
    $total_user_sessions mysql_num_rows($gu_query);
    if(
    $total_user_sessions){
        
    $username_array = array();
        
    $userid_array = array();
        while(
    $gu_array mysql_fetch_array($gu_query)){
            if(
    strlen(trim($gu_array["data"]))){
                
    $strings split(";"$gu_array["data"]);
                for(
    $x 0$x sizeof($strings); $x++){
                    if(
    strlen($strings[$x])){
                        if(
    eregi("^username"$strings[$x])){
                            
    $parts split(":"$strings[$x]);
                            
    $username_array[] = eregi_replace("\""""$parts[2]);
                        }
                    }
                }
            }
        }
        
    $status="<img align=\"top\" src=\"$base_url/images/user_offline.gif\" hspace=\"3\" vspace=\"1\" alt=\"Offline\" title=\"Offline\">";
            
    $user_status="Offline";
        if(
    sizeof($username_array)){
            
    $un array_unique($username_array);
            for(
    $z 0$z sizeof($un); $z++){
              if(
    $un[$z] == $array[user_name]) {
                    
    $status="<img align=\"top\" src=\"$base_url/images/user_online.gif\" hspace=\"3\" vspace=\"1\" alt=\"Online\" title=\"Online\">";
                    
    $user_status="Online";
                break;
              }
            }
        }
    }


    $image_src '<img src="' $base_url '/images/notfound_image.gif">';
    if(
    check_approved_image($profile_id)) {
      
    $i_path get_image_path1($pid,1);
      
    $i_size getimagesize($i_path);
      if(
    $i_size[0] > $max_image_width) {     $iw $max_image_width;   } else {    $iw $i_size[0];  }
        
    $image_src="<img src=\"image1.php?id=$pid&p=1\" border=0 alt=\".: $array[user_name] :.\" title=\".: $array[user_name] :.\" width=" $iw ">";
    }


    $tpl->assign(array('EXTRA_PHOTOS' => $extra_photos,
                       
    'STATUS' => $status,
                       
    'USER_STATUS' => $user_status,
                       
    'AVERAGE_RATING' => $array[average_rating],
                       
    'TOTAL_POITS' => $array[total_points],
                       
    'TOTAL_RATINGS' => $array[total_ratings],
                       
    'USER_NAME' => $array[user_name],
                       
    'AGE' => $array[age],
                       
    'DESCRIPTION' => $array[description],
                       
    'STATE' => $array[state],
                       
    'COUNTRY_IMAGE' => $array[country],
                       
    'COUNTRY' => $country,
                       
    'URL' => $array[url],
                       
    'QUOTE' => $array[quote],
                       
    'DAYS' => $days,
                       
    'HOURS' => $hours,
                       
    'MINS' => $mins,
                       
    'ADDITIONAL_FIELDS' => view_additional_fields($profile_id),
                       
    'IMAGE_SRC' => $image_src,
                       
    'I'=> $_GET['pid']
                       ));
      
    $tpl->parse('PROFILE_CONTENT''favorites_profile_content');
      
    $profile_content $tpl->fetch('PROFILE_CONTENT');
      
    $profile_content table("Profile"$profile_content);
    }



    $title ="Buddies";


    $sql "select * from $tb_favourites where user_id='$user_id'";
    $res mysql_query($sql) or die(mysql_error());
    if(
    mysql_num_rows($res) == ) {
      
    $tpl->parse('FAV_TABLE''favorites_fav_table_empty');
    }
    else {

      while(
    $rs mysql_fetch_array($res)) {
        
        
    $img_src $base_url "/images/quest.jpg";
        
        
    $fav_name get_username($rs['fav_user_id']);
                  
    $imgid=$rs['fav_user_id'];
        
    $imgsql ="select image_status from $tb_users where id='$imgid' ";
        
    $imgres =mysql_query($imgsql) or die(mysql_error());
        
    $imgstat=mysql_fetch_row($imgres);
        
    $img_stat=$imgstat[0];
        
        
    $tpl->assign(array('IMG_LINK_START' => '',
                           
    'IMG_LINK_END' => ''));
        
        
        if(
    check_approved_image($rs['fav_user_id'])) {
          
    $img_src $base_url "/image1.php?id=" $rs['fav_user_id'] . "&p=1";
        }
        
        
    $tpl->assign(array('FAV_NAME' => $fav_name,
                           
    'IMG_SRC' => $img_src,
                           
    'FAV_USER_ID' => $rs['fav_user_id']));

       if (
    $img_stat=='approved') {                  
         
    $tpl->assign(array('IMG_LINK_START' => '<a class="link01" href="' $base_url '/?i=' $rs['fav_user_id'] . '">''IMG_LINK_END' => '</a>')); 
         
    $profile_str="<a class=\"link01\" href=\"$base_url/favourites.php?pid=$imgid\">Profile</a>";
         
    $message_str="<a href=\"$base_url/message.php?i=$imgid\" class=\"link01\">Message</a>";
      }
     else 
      {
         
    $profile_str="Profile";
         
    $message_str="Message";
       }                       
        
        
    $tpl->assign(array('PROFILE' =>$profile_str'MESSAGE' =>$message_str));
        
    $tpl->parse('FAV_ROWS''.row_fav_table');
      }
      
    $tpl->parse('FAV_TABLE''favorites_fav_table');
    }


    $tpl->parse('CONTENT_''favorites_content');
    $content $tpl->fetch('CONTENT_');


    if(!isset(
    $_SESSION['userid'])){
      
    $tpl->parse('CONTENT_''favorites_content_must_login');
      
    $content $tpl->fetch('CONTENT_');
    }

    $content table($title$content) . $profile_content;




    $tpl->assign(array('CONTENT_TEXT' => $content));
    $tpl->parse('PAGE_''main');
    $final_output $tpl->fetch('PAGE_');







    ////echo $final_output;
    include ("copy.php");
    ?>
    Keep in mind, the second function relies on the person being logged in and viewing their own buddies. I want everyone to see this persons buddy list.

    Also important, this code uses templates to show the content on the pages.

    Any help would be greatly aprretiated!
    Bill

  • #2
    Regular Coder mlse's Avatar
    Join Date
    Mar 2005
    Posts
    624
    Thanks
    20
    Thanked 19 Times in 18 Posts
    I presume you have a database table containing the UIDs of each user's buddys, indexed by the user's own UID (let's call the table BUDDIES, for the sake or argument). Let's also say that each user's general info is stored in a table called USERS, also indexed by UID.

    In that case, I suggest that all you need is a single SELECT query to retrieve the UIDs of the user's buddies from the BUDDIES table and cross-reference them back into the USERS table to obtain whatever additional info you want WRT each buddy, and stuff it into an appropriately structured associative array, for example (the built-in PHP sql functions will do that for you).

    This will work for any input UID. You could wrap this functionality into a single function in a file and import that file into all files where you require the function, then just tabulate the results of calling the function, as required.

    I hope that helps!

    Mike.
    Die Welt ist ein Irrenhaus und hier ist die Zentrale!


  •  

    Posting Permissions

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