我如何连接id和#并将其放在href标签中? 这段代码对我不起作用

$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.

You need to enclose the string in double quotes (and escape the ones inside of the string)

 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.