hello i have a problem understanding how a function works

for example i wrote this php code

<?php
$face = $Wall->Profilepic($profile_pic_path);
$query = mysql_query("SELECT * FROM `messages` WHERE type ='A' AND uid_fk = '$uid'");
while($row=mysql_fetch_array($query))
{
echo '<a href="'.$base_url.'roves/'.$row['msg_id'].'" ><img src="'.$face.'" class="small_face" original-title="'.$row['message'].'" ></a>';
}
?>

and i named a variable $face so i can take the image from this function

public function Profilepic($uid,$base_url) 
     {

         $uid=mysql_real_escape_string($uid);
         $query = mysql_query("SELECT * FROM user_uploads WHERE uid_fk='$uid'") or die(mysql_error());
         $row=mysql_fetch_array($query);

              /*Art Uploaded Picture */
                if ($row['type']== 'A')
                {
                      if(!empty($row['image_path']))
                      {
                      $profile_pic_path=$base_url.'uploads/photos/';
                      $data= $profile_pic_path.$row['image_path'];
                      return $data;
                      }
                      else
                      {
                      $data=$base_url."wall_icons/profile-audio.jpg";
                      return $data;
                     }
                }
                elseif ($row['type']== 'T')
                {
                      if(!empty($row['image_path']))
                      {
                      $profile_pic_path=$base_url.'uploads/texts/images/';
                      $data= $profile_pic_path.$row['image_path'];
                      return $data;
                      }
                      else
                      {
                      $data=$base_url."wall_icons/text_icon.jpg";
                      return $data;
                     }
                }
                elseif ($row['type']== 'V')
                {
                      if(!empty($row['image_path']))
                      {
                      $profile_pic_path=$base_url.'uploads/videos/images/';
                      $data= $profile_pic_path.$row['image_path'];
                      return $data;
                      }
                      else
                      {
                      $data=$base_url."wall_icons/video-icon.jpg";
                      return $data;
                     }
                }
     }

what am i doing wrong?

Recommended Answers

All 4 Replies

The first this is you are not using the OOP properly here. Just using in the function once. Try to have another function for waht you wrote the sql in the begining.

I am not much pro in OOP but i know that you passing wrong no of parameter in the function see in function declaration-

function Profilepic($uid,$base_url) 

and here you go while calling

$face = $Wall->Profilepic($profile_pic_path);

where is second parameters?

As an additional observation - $Wall should be declared somewhere as well ?

$Wall = new <ObjectName> ( Params );

Yes Andre the $wall is called on a included file.

So change
$face = $Wall->Profilepic($profile_pic_path);
to
$face = $Wall->Profilepic($uid,$base_url);

still the same

The function parameters are Profilepic($uid,$base_url)

You seem to be passing in different variables.

I would assume that $base_url is the scripting path for the hosted domain so for a Linux hosted site, it would most likely be something like /var/www/vhosts/example.com/htdocs but you'll need to confirm that with your host if it's not your own server. This would probably be declared either earlier in the file or in an include.

$uid is obviously the unique identifier for the user you're getting the profile picture for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.