help with this php code please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sung7psi
Forum Newbie
Posts: 8
Joined: Fri Dec 10, 2004 7:51 pm
Location: marietta, GA

help with this php code please

Post by sung7psi »

i have the following php code on my site and need the link to open in a new window...where do i add target="_blank"
not sure as to where to put it in

if ($bannerDetails['type']=="custom") {
echo "<a href=\"click.php?refid=".$bannerDetails['id']."\" target=\"new\"><img src=\"".$bannerDetails['imgpath']."\" alt=\"".$bannerDetails['alttext']."\" border=\"0\"><br>".$bannerDetails['textunder']."</a>";
// echo "<a href=\"".$bannerDetails['url']."\"><img src=\"".$bannerDetails['imgpath']."\" alt=\"".$bannerDetails['alttext']."\" border=\"0\"><br>".$bannerDetails['textunder']."</a>";
} else if ($bannerDetails['type']=="code") {
echo $bannerDetails['banner_code'];
}
}
mysql_free_result($getAdvert); ?> </td>

thanks
sung
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

first ask yourself where you put the

Code: Select all

tags....
sung7psi
Forum Newbie
Posts: 8
Joined: Fri Dec 10, 2004 7:51 pm
Location: marietta, GA

Post by sung7psi »

i'm a newbie to php and not quite familiar with it
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

well, i see you are a newbie on this forum too... might want to read the sticky with title: posting code ... first
sung7psi
Forum Newbie
Posts: 8
Joined: Fri Dec 10, 2004 7:51 pm
Location: marietta, GA

Post by sung7psi »

sorry about that

Code: Select all

if ($bannerDetails['type']=="custom") { 
echo "<a href="click.php?refid=".$bannerDetails['id']."" target="new"><img src="".$bannerDetails['imgpath']."" alt="".$bannerDetails['alttext']."" border="0"><br>".$bannerDetails['textunder']."</a>"; 
// echo "<a href="".$bannerDetails['url'].""><img src="".$bannerDetails['imgpath']."" alt="".$bannerDetails['alttext']."" border="0"><br>".$bannerDetails['textunder']."</a>"; 
} else if ($bannerDetails['type']=="code") { 
echo $bannerDetails['banner_code']; 
} 
} 
mysql_free_result($getAdvert); ?> </td>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Change the "new" in target=\"new\ to "_blank".
sung7psi
Forum Newbie
Posts: 8
Joined: Fri Dec 10, 2004 7:51 pm
Location: marietta, GA

Post by sung7psi »

tried changing "new" to _blank
but it didn't work
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well that code is just way too hard to read formatted like that. I rewrote parts of it, I didn't test it but the target="_blank" was in the wrong place.

Code: Select all

<?php
if ($bannerDetails['type']=="custom")
  {
  $data = ''
  . '<a  target="_blank" href="click.php?refid=' . $bannerDetails['id'] . '">'
  . '<img src="' . $bannerDetails['imgpath'] . '" alt="' . $bannerDetails['alttext'] . '" border="0"><br>' . $bannerDetails['textunder'] . '</a>';
  // echo "<a href="".$bannerDetails['url'].""><img src="".$bannerDetails['imgpath']."" alt="".$bannerDetails['alttext']."" border="0"><br>".$bannerDetails['textunder']."</a>";
  echo $data;
  }
  elseif ($bannerDetails['type']=="code")
  {
  echo $bannerDetails['banner_code'];
  }
  mysql_free_result($getAdvert);

?></td>
sung7psi
Forum Newbie
Posts: 8
Joined: Fri Dec 10, 2004 7:51 pm
Location: marietta, GA

Post by sung7psi »

still didn't work
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Yes it does...

Code: Select all

<?php
$data = ''
  . '<a  target="_blank" href="click.php?refid=' . $bannerDetails['id'] . '">'
  . '<img src="' . $bannerDetails['imgpath'] . '" alt="' . $bannerDetails['alttext'] . '" border="0"><br>' . $bannerDetails['textunder'] . '</a>';
echo $data;

?>
Tries to load an image, and when clicked, opens a new browser window.
sung7psi
Forum Newbie
Posts: 8
Joined: Fri Dec 10, 2004 7:51 pm
Location: marietta, GA

Post by sung7psi »

i changed the part of the code in the script and i get error messages
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well post the code and the error message if you want help.
Post Reply