Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP function How to call in HTML page

Status
Not open for further replies.

zrazzaq

MIS
Apr 13, 2005
102
US
I have the following code and I have placed it in my main.html page. I do not know how to call the function showbanners.
Code:
<?
function show_banners() 
{

		//get the banners
		$q1 = "select * from platinum_banners order by rand() limit 0,5";
		$r1 = mysql_query($q1) or die(mysql_error());

		$b = mysql_num_rows($r1);

		if($b < '5')
		{
			for($bb = '1'; $bb <= (5 - $b); $bb++)
			{
				$banners .= "<td align=center width=154 height=70><a href=\"contact_us.php\"><img src=\"ad_here.gif\" border=1 style=\"border-color:black\"></a></td>\n\t";
			}
		}

		while($a1 = mysql_fetch_array($r1))
		{
			$banners .= "<td align=center width=154 height=70><a href=\"$a1[BannerURL]\" target=_blank><img src=\"banners/$a1[BannerFile]\" border=0 width=120 height=60></a></td>\n\t";
		}

		$banners .= "</tr>\n</table>\n\n";

	return $banners;
}
?>
<table border="0" cellpadding="0" cellspacing="0" width="770" class="pg" bgcolor="#ffffff">
  <tr>
  <td width="10" valign="top"><?=show_banners();?></td>
What am I doing wrong???
Thanks
Z
 
nothing much wrong. remove the semicolon though.
Code:
  <td width="10" valign="top"><?=show_banners()?></td>
i think you should change your conditionals and for loops in the function to refer to numbers rather than strings. and if you want to avoid notices you should declare $banners = ""; at the start of your function.
 
i've tweaked the function a bit. not sure it makes any difference though!

Code:
function show_banners() 
{
        //get the banners
        $q1 = "select * from platinum_banners order by rand() limit 5";  // don't need the offset
        $r1 = mysql_query($q1) or die(mysql_error());
        $padding = "<td align=center width=154 height=70><a href=\"contact_us.php\"><img src=\"ad_here.gif\" border=1 style=\"border-color:black\"></a></td>\n\t";
$banners = "<table><tr>";
$bannersI =""; //innerhtml variable
$cnt = 1;  //counter variable
        while($a1 = mysql_fetch_assoc($r1)): // changed to associative array only
            $bannersI .= "<td align=center width=154 height=70><a href=\"".$a1['BannerURL']."\" target=_blank><img src=\"banners/".$a1['BannerFile']."\" border=0 width=120 height=60></a></td>\n\t";
        $cnt++;
endwhile;
for ($i=$cnt; $i<5, $i++):
        $bannersI = $padding . $bannersI; 
endfor;
$banners .= $banners . $bannersI . "</tr>\n</table>\n\n";
    return $banners;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top