954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to use php variable in href?

Hi all,
I want to use php variable for example $Lang[0] in the href as

where $Lang[0]="http://www.dailyhungama.com"
thanks in advance

ramukumar
Newbie Poster
7 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
Hi all, I want to use php variable for example $Lang[0] in the href as where $Lang[0]="http://www.dailyhungama.com" thanks in advance
<a href="<?= $Lang[0] ?>" target="_blank">My Lang Link</a>
techniner
Posting Pro
527 posts since May 2005
Reputation Points: 12
Solved Threads: 19
 

ok but my page is full php likr
<?
$dbhost = 'xxxxxxxxxxx;
$dbuser = 'xxxxxxxx';
$dbpass = 'xxx';
$dbname = 'xxxxx';
$TABLE_NAME='xxxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
mysql_select_db($dbname, $conn) or die(mysql_error());
$keyword=$_GET[key];
$result = mysql_query("SELECT NewsPaper,Link,Lang FROM xxxx WHERE State LIKE '%$keyword%'",$conn);
if (!$result)
{
die('Query failed: ' . mysql_error());
}
/* fetch rows in reverse order */
for ($i = 0; $i < mysql_num_rows($result); $i++) {
if (!mysql_data_seek($result, $i)) {
echo "Cannot seek to row $i: " . mysql_error() . "\n";
continue;
}

if (!($row = mysql_fetch_assoc($result))) {
continue;
}


$NewsPapers[]=$row['NewsPaper'];
$Links[]=$row['Link'];

}
$nor=sizeof($NewsPapers);

for($j = 0; $j < mysql_num_rows($result); $j++) { print " ".$Link[$j]."\" target=_blank> news3.gif\"".$NewsPapers[$j]." "; } ?>


help me in this

ramukumar
Newbie Poster
7 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
echo "<tr><td><a href='$Link[$j]' target='_blank'> <img src='/images/news3.gif' /> <font color='#FFFFFF' size='3'>$NewsPapers[$j]</font></a></td>";


the html is screwed up,
a mix of xhtml and html,
attributes are required to be quoted,
dtd is required
some browsers will fail to render on this type of error

wrape code in[code=language] [/code] tages where language is html php asp etc. to make viewing simpler

like the instructions on the top of the page tell you

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

if you want to use in side the html tag or href
use like this
<?php echo $Lnag[0] ?>
this is the answer for you question.
if any dobut reply me.

dhanushree
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
if you want to use in side the html tag or href use like this <?php echo $Lnag[0] ?> this is the answer for you question. if any dobut reply me.


Do not use this code in your file, the poster has not bothered to read any part of your existing code and this generic crap will kill php at the first ?>

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

Looks like the other guys have allready answered this, But in case not:

$url = 'http://www.mysite.com'; // or $url = $lang[0];
$link = 'mylink';
echo $link;

Thats the idea. you may need to modify slighty for your exact need but should do the trick.

TheWabbit
Newbie Poster
2 posts since Mar 2010
Reputation Points: 13
Solved Threads: 0
 

Many thanks, Little Jon - that's very helpful

Miles

<a href="<?= $Lang[0] ?>" target="_blank">My Lang Link</a>
milesreid
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

also

$url['google'] = "http://www.google.com";

echo "<a href=\"{$url['google']}\" target=\"_blank\">Link</a>";
xaeon
Newbie Poster
2 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

thanks a ton "the wabbit".....ur code worked awesome

aru211285
Newbie Poster
22 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: