Jump to content


Photo

Would like some help with syntax


  • Please log in to reply
3 replies to this topic

#1 cybertick

cybertick
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 March 2006 - 08:35 PM

I am trying to rework someone elses code to fit my needs. Problem is I do not fully understand the way they wrote the code.

See the example:
<? $sql -> db_Select("buddy", "*", "buddy_user=". USERID." AND buddy_buddy=".$_POST['buddy']);?>


The way I understand is like this...

$sql : is an array

-> : says this is how we are filling the array


db_Select : select the buddy table int the current DB

"*" : get all fields in the row (the table only has 3 columns buddy_id, buddy_user, buddy_buddy)

"buddy_user=". USERID." AND buddy_buddy=".$_POST['buddy'] : This is the part that is throwing me

Mainly the USERID, can someone explain this for me? Where does it come from? Is it just an undeclared local variable?



#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 25 March 2006 - 09:49 PM

It's a constant since USERID doesn't have a dollar sign in front of it.

Look for it being set somewhere using define().

See this for more info:
[a href=\"http://us2.php.net/constants\" target=\"_blank\"]http://us2.php.net/constants[/a]


It could be a column name in a table too but the way it's used, I very much doubt that.


p.s. This "->" doesn't mean filling an array. It's related to object oriented programming. You're mixing it up with the "=>" array syntax. i.e. $ary = array('key' => 'value, 'key2' => 'value2').

#3 cybertick

cybertick
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 March 2006 - 10:42 PM

Hey thanks toplay. I know I have lots to learn yet. I am using e107 and found that the define("USERID", $result['user_id']); line is located in the class2.php.

Well I am about to loose my mind trying to figure this out...so I am back for some more help.
I am trying to rewrite the following code to do something a little different than what it does as is. Right now it does as it should, gives me a list of site users and let's me know if they are on the site or not.

// Populate the buddy list
    $text="";
    $sql -> db_Select("bf2buds", "bf2buds_buddy", "bf2buds_user=". USERID);
    while(list($bf2buds_id) = $sql-> db_Fetch()){
      $sql2=new db;
      $sql2 -> db_Select("user", "user_login,user_name,user_id", "user_id=".$bf2buds_id);
      if ($row = $sql2 -> db_Fetch()) {
            extract($row);



        $sql3=new db;
            $sql3 -> db_Select("online", "*", "online_user_id='".$user_id.".".$user_name."'");


            if ($row3 = $sql3 -> db_Fetch()){


              $text .="<img src=\"".e_PLUGIN."bf2buds_menu/images/online.png\" alt=\"online\"> ";
              
                                            } else {

              $text .="<img src=\"".e_PLUGIN."bf2buds_menu/images/offline.png\" alt=\"offline\" > ";

                   }
            if ($urname <> "" ) {

            $text.="<a href=\"".e_BASE."user.php?id.$user_id\">".($pref['realname']==1 && $user_login <> "" ? $user_login : $user_name)." [<a href=\"".e_SELF."?delbuddy=".$user_id."\" border=0>".BUDDYLAN_2."</a>]<br>";

                                } else {

            $text.="<a href=\"".e_BASE."user.php?id.$user_id\">".($pref['realname']==1 && $user_login <> "" ? $user_login : $user_name)." [<a href=\"".e_SELF."?delbuddy=".$user_id."\" border=0>".BUDDYLAN_2."</a>]<br>";

                 }

                                     }

                                                 }

What I am trying to have it do is let me know if a person on my list is playing BF2.

I have a DB(I'll call it BF2) outside of the DB(I'll call it e107) used by this code that as this information in it that I need.

Here is the layout:

DB : Table : Columns
BF2 : players : playername, playerpid
e107 : user : user_id, user_name, login_name
e107 : user_extended : user_extended_id, user_pid, userbf2name
e107 : buddy : buddy_id, buddy_user, buddy_buddy

I think I need at least 2 more $sql -> lines......but have no clue on how to get them working.

I know that:
e107.user.user_id = e107.user_extended.user_extended_id
e107.user_extended.user_pid = BF2.playerpid
e107.user_extended.user_extended_id will get me the user_pid

If anyone could help I would be most grateful!




#4 cybertick

cybertick
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 27 March 2006 - 01:56 AM

I think I have made some progress, but still have something I cannot quite figure out.
From the code below what does this line mean?
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] if ($row3 = $sql3 -> db_Fetch()){ [/quote]

I usually will do an echo to the page to see what is in an array, but this is not an array from what toplay said above and I cannot figure out out how to see what this holds. I am sure it would help me in figuring out my problem to know what is in there.

I plan to change the code to look for a new item that is being placed in this e107_user_extended table.

          $sql3=new db;
          $sql3 -> db_Select("e107_user_extended", "*", "online_user_id='".$user_id.".".$user_name."'");


            if ($row3 = $sql3 -> db_Fetch()){


              $text .="<img src=\"".e_PLUGIN."bf2buds_menu/images/online.png\" alt=\"online\"> ";

                                            } else {

              $text .="<img src=\"".e_PLUGIN."bf2buds_menu/images/offline.png\" alt=\"offline\" > ";

                   }
            if ($urname <> "" ) {

            $text.="<a href=\"".e_BASE."user.php?id.$user_id\">".($pref['realname']==1 && $user_login <> "" ? $user_login : $user_name)." [<a href=\"".e_SELF."?delbuddy=".$user_id."\" border=0>".BUDDYLAN_2."</a>]<br>";

                                } else {

            $text.="<a href=\"".e_BASE."user.php?id.$user_id\">".($pref['realname']==1 && $user_login <> "" ? $user_login : $user_name)." [<a href=\"".e_SELF."?delbuddy=".$user_id."\" border=0>".BUDDYLAN_2."</a>]<br>";

                 }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users