rscott7706 Posted July 15, 2008 Share Posted July 15, 2008 Hey all, I have a unique problem. Here is a snippet from my code: echo "<a target=\"_blank\" href='$row[link]'> Go there</a>"; Now, I need to have some links to target an Iframe named "container", but others to target _blank. In other words, I have some links that are targeted to my site only, but some to friends of the Chamber that must open in a new window. I know I could build in to my database, a field that would allow target=container or target=_blank, but how do i get my PHP to recognize this, and plop it in after the opening tag <a and before the href= part? Egads.... Thanks in advance... Ron Scott Quote Link to comment Share on other sites More sharing options...
widox Posted July 15, 2008 Share Posted July 15, 2008 Well, how are you recognizing which links are targeting container and which are targeting blank? Do you already have something in your DB that identifies links as internal or external? Some more code and an example link would be helpful. Quote Link to comment Share on other sites More sharing options...
rscott7706 Posted July 15, 2008 Author Share Posted July 15, 2008 widox - Thanks for your quick response. The link comes from the database named "link". In the coding I just made it automatically go to _blank, but soon realized I want the base links (my site links) to go to an Iframe called "container", but external links to go to _blank. I could have the link in link field in the database determine the target, but inexperienced Chamber office works will be putting the link info in the database, so I wanted to keep it simple for them. Here is more code, leaving out log on info: mysql_select_db("lakesie7_articles"); $query = "SELECT * FROM coming_events ORDER by sort"; $result = mysql_query($query) or die(mysql_error()); echo "<font face=\"arial\">"; while($row = mysql_fetch_array($result)){ echo "<font color= maroon><font size=2><b>"; echo $row['event']; echo "</b></font>"; echo "<font color= black><font size=2>"; echo $row['article']; echo "</font>"; echo "<a target=\"_blank\" href='$row[link]'> Go there</a>"; echo "</font>"; echo "<br />"; echo "<br />"; } ?> Thanks again... Ron Quote Link to comment Share on other sites More sharing options...
widox Posted July 15, 2008 Share Posted July 15, 2008 OK. What is the format of your $row['link']? Are they absolute URL's or relative? If the former, you can simply check for your domain. For the latter, external URL's must begin with http:// so you could check if that exists. Then you just alter the link HTML accordingly. Quote Link to comment Share on other sites More sharing options...
rscott7706 Posted July 15, 2008 Author Share Posted July 15, 2008 The links are all absolute - they have to be for the externals for sure. But for consistency, I did the internals as absolute also. examples: external: http://www.jcfeedandsupply.com/events.htm internal: http://www.lakesideca.com/lakeside/events/revitilaztion.htm I don't understand your reference to "Then you just alter the link HTML accordingly." Everything I am doing here is through the database and PHP coding - no HTML (to that degree). Pardon me for not getting that part... Thanks again... ??? Ron Scott Quote Link to comment Share on other sites More sharing options...
widox Posted July 15, 2008 Share Posted July 15, 2008 Ok, that makes it easy to approach. while($row = mysql_fetch_array($result)){ if(strpos($row['link'], 'lakesideca.com') === false) { $linkTarget = '_blank'; } else { $linkTarget = 'container'; } echo "<font color= maroon><font size=2>"; echo $row['event']; echo "</font>"; echo "<font color= black><font size=2>"; echo $row['article']; echo "</font>"; echo "<a target=\"$linkTarget\" href='$row[link]'> Go there[/url]"; echo "</font>"; echo ""; echo ""; } The if statement simply checks if the string "lakesideca.com" (internal links) is in the link field, and if so sets $linkTarget to "container", otherwise it must be external so it get set to _blank. That should get you on your way. caution: quick off-the-cuff untested code Quote Link to comment Share on other sites More sharing options...
rscott7706 Posted July 15, 2008 Author Share Posted July 15, 2008 Thanks my friend - I will run with it. This gets me started and I should be able to bull dog it from here. I will let you know how it goes tonight. Thanks!! Ron Scott Quote Link to comment Share on other sites More sharing options...
rscott7706 Posted July 15, 2008 Author Share Posted July 15, 2008 widox, Works perfectly - thank you so much. I appreciate your time and effort!! Ron Scott Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.