Jump to content

Archived

This topic is now archived and is closed to further replies.

cybertick

Would like some help with syntax

Recommended Posts

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:
[code]<? $sql -> db_Select("buddy", "*", "buddy_user=". USERID." AND buddy_buddy=".$_POST['buddy']);?>[/code]


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?

Share this post


Link to post
Share on other sites
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').

Share this post


Link to post
Share on other sites
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.

[code]// 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>";

                 }

                                     }

                                                 }[/code]

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:

[b]DB[/b] : [b]Table[/b] : [b]Columns[/b]
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!


Share this post


Link to post
Share on other sites
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.

[code]
          $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>";

                 }
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.