Jump to content

[SOLVED] My Function dont work. Why not???


StefanRSA

Recommended Posts

For the first time I have the guts to try creating my own function.  ::)

It is not working but I don't really understand why. Please have a look and direct me in fixing this typical php beginner error...

 

Thanks

 

function GoogleAd()
{
if ($catkey==1){
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* PROPERTY */
google_ad_slot = "7983841197";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else if ($catkey==2){
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* STUFF FOR SALE */
google_ad_slot = "5536810507";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else if ($catkey==3){
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* CARS FOR SALE */
google_ad_slot = "0191739856";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else if ($catkey==4){
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* JOBS */
google_ad_slot = "7640366802";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else if ($catkey==5){
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* BUSINESS SERVICES */
google_ad_slot = "3285320338";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else if ($catkey==6){
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* COMMUNITY */
google_ad_slot = "7462364297";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else if ($catkey==7){
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* EDUCATION */
google_ad_slot = "8279843684";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else if ($catkey=={
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* PERSONALS */
google_ad_slot = "5750199803";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
else {
echo '<script type="text/javascript"><!--
google_ad_client = "pub-0928155608609322";
/* PERSONALS */
google_ad_slot = "5750199803";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>';
}
}

Link to comment
https://forums.phpfreaks.com/topic/166242-solved-my-function-dont-work-why-not/
Share on other sites

i haven't looked through the whole function, so there could be syntax errors, but the logical reason why the function doesn't work (which although you haven't explained HOW it doesn't work, i assume it's because it's always showing personals) is because it relies on $catkey, which is never passed to the function.

 

function GoogleAd($catkey)
{
  ...
}

 

and then when you call it, you'll need to pass it the $catkey variable.

 

this function could be a lot cleaner if you used a switch() statement.

Archived

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

×
×
  • Create New...

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.