Solved

passing function to a function?

Posted on 2009-05-15
9
303 Views
Last Modified: 2012-05-07
Hello, I am trying to pass a function to a function in PHP, but it seems that only the function that is being passed works.

The Value of woo_get_custom_banner('bannerIDside') is 10 and the only thing that shows up on the page is 10 but what SHOULD be showing up is a banner!

if I use
mba_display_banner(10);
the function works perfectly.

any ideas??
<div id="rightbanner">
<?php mba_display_banner(woo_get_custom_banner('bannerIDside')); ?>
</div>

Open in new window

0
Comment
Question by:b1xx1b
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 9

Expert Comment

by:wellhole
ID: 24398945
What does mba_display_banner(10) do for you? If it does the same thing as what you posted above, then your problem lies in mba_display_banner.
0
 

Author Comment

by:b1xx1b
ID: 24398951
if I use
mba_display_banner(10);
the function works perfectly and correctly displays the banner (with banner_id = 10)
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24398959
Oops.. didn't read the whole thing. Are you absolutely sure woo_get_custom_banner is working correctly?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:b1xx1b
ID: 24398968
( i edited the post AFTER you commented ... you didn't miss it :))
yes, I am positive the function works perfectly.
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24398977
Would you mind sharing both functions?
0
 

Author Comment

by:b1xx1b
ID: 24398995
sure here they are:

function mba_display_banner(&$banner_id) {
      global $MBPBannerAdsPlugin;
      global $banner_id;
      if ( !is_admin() ) {
            if ( intval($banner_id) > 0 ) {
                  $banner_filter = "id='$banner_id'";
            } else {
                  $banner_filter = "name='$banner_id'";
            }
            $sql = "SELECT id,url,link,in_new_win,ad_type,text_ad_code FROM $MBPBannerAdsPlugin->mban_banner_table WHERE status='1' AND {$banner_filter}";
            $rs  = mysql_query($sql);
            $id   = array();
            $url  = array();
            $link = array();
            $in_new_win = array();
            $text_ad_code = array();
            $zone_properties = array();
            while ( $data = @mysql_fetch_assoc($rs) ) {
                  $cnt++;
                  if ( $data['ad_type'] == 1 ) {
                        $id[] = $data['id'];
                        $text_ad_code[] = $data['text_ad_code'];
                  } else {
                        $id[]   = $data['id'];
                        $url[]  = $data['url'];
                        $link[] = $data['link'];
                        $in_new_win[] = $data['in_new_win'];
                  }
            }
            if ( count($id) > 0 ) {
                  $banner_output = $MBPBannerAdsPlugin->__mbanGetBanner($id,$url,$link,$in_new_win,$zone_properties,$text_ad_code);
                  echo $banner_output;
                  //echo $sql;
            }
      }
}



function woo_get_custom_banner($key) {

global $post;
$custom_field = get_post_meta($post->ID, $key, true);
if ($custom_field) {
      $custom_field = stripslashes($custom_field);
?>
<?php echo $custom_field; ?>
<?php
}
else { //else, return
      return;
}
}
0
 
LVL 9

Accepted Solution

by:
wellhole earned 500 total points
ID: 24399006
Well theres your problem. woo_get_customer_banner is ECHOING the result instead of returning it.
0
 

Author Comment

by:b1xx1b
ID: 24399007
Note:  I have used the function like this:
function mba_display_banner(&$banner_id)
and with the & like this
function mba_display_banner($banner_id)

and still does not work correctly.
0
 

Author Comment

by:b1xx1b
ID: 24399053
Thanks!  That did the trick.  duh.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question