简体   繁体   中英

How can i concatenate the id and the # and put it in the href tag? This code is not working for me

$temporaryID = $row->id; //data row ID from table
$concat = "#".$temporaryID; //concatenate it for href

if($x % 2==1){
    echo '<li class="featuredNews-li" href="$concat" data-toggle="tab">';
 }
?>

Trying to concatenate the # with the data id to put it the href tag.

您需要将字符串用双引号引起来(并在字符串内转义)

 echo "<li class=\"featuredNews-li\" href=\"$concat\" data-toggle=\"tab\">";

Change

$temporaryID = $row->id;
$concat = "#".$temporaryID;

if($x % 2==1){
    echo '<li class="featuredNews-li" href="$concat" data-toggle="tab">';
 }

To:
eliminating $concat

$temporaryID = '#' . $row->id;
if($x & 1){
    echo "<li class=\"featuredNews-li\" href=\"$temporaryID\" data-toggle=\"tab\">";
 }

I prefer $x & 1 rather than $x % 2==1 because the AND function is a single micro instruction. Your method is a math function and comparison.

But that is here nor there. Double quoted string with escaped double quote within the sting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM