User $variables through-out plugin with out using globals.
-
I do apologize if my question is a big confusing.
Im building a plugin that takes data and displays it in a loop. Then I would take the ID number and get results from another table.
egglobal $wpdb, $bp; $fname = 'mike'; $lname= 'freemond'; $entries = $wpdb->get_results("SELECT * FROM table WHERE column1 = $fname AND column2 = $lname ORDER BY id"); if( $entries ) { foreach( $entries as $entry ) { $contentid = $entry->id, $firstname = $entry->content1, $lastname = $entry->content2, $city = $entry->content3, ); echo $contentid; echo $firstname; echo $lastname; echo $city; $phonenumber = $wpdb->results("SELECT * FROM contact WHERE person = $contentid"); echo $phonenumber; ... ect... } }
(This is just an example code..)
so the above loop will display id,first name, last name, city, and phonenumber.
What I would like to do is have a function for the phone numbers
eg.function phonenumber(){ global $wpdb; $phonenumber = $wpdb->results("SELECT * FROM contact WHERE person = $contentid"); echo $phonenumber; }
Then use it in my loop.
global $wpdb, $bp; $fname = 'mike'; $lname= 'freemond'; $entries = $wpdb->get_results("SELECT * FROM table WHERE column1 = $fname AND column2 = $lname ORDER BY id"); if( $entries ) { foreach( $entries as $entry ) { $contentid = $entry->id, $firstname = $entry->content1, $lastname = $entry->content2, $city = $entry->content3, ); echo $contentid; echo $firstname; echo $lastname; echo phonenumber(); <-- here. ... ect... } }
I looked into add_filter/apply_filters. But I couldn’t find a simple break down of an example. I was able to do the following.
function a($one){ $one = '1'; return $one; }add_filter('addthis', 'a'); function b(){ $one = apply_filters('addthis', 'a'); $two = '2'; $three = $two + $one; echo $three };
$three would echo 3.
But it didn’t work as planned when I put it all together.
Once again, I do apologize if my question is a bit confusing.
Many thanks -Mike.
- The topic ‘User $variables through-out plugin with out using globals.’ is closed to new replies.