Forum Moderators: coopster

Message Too Old, No Replies

echo <a href=

avoiding syntax error with echo and <a href=

         

awkale

7:53 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



I have a repeat region and each entry is linking to it's detail page. I would like to not always have an entry clickable, i.e. no href. I've been trying the conditional statement below and having no success after reading all the other posts.

This is the error I keep getting:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/9501/domains/testing/html/testing/portfolio/portfolio_all_if.php on line 190

Here is the unmodified region with no IF statment:

<a href="proj_detail.php?job_id=<?php echo $row_proj_list_all['job_id'];?>"><strong><?php echo $row_proj_list_all['job_name'];?></strong><br />
<?php echo $row_proj_list_all['job_sub_name'];?>
</a>

Here is my attempt at making the href appear if the correct condition is met:

<?php
if ($totalRows_proj_list_all['job_detail'] == 0) { // Show if recordset not empty
echo "<a href=\"proj_detail.php?job_id=$row_proj_list_all['job_id']\"><strong> $row_proj_list_all['job_name'] </strong><br />
$row_proj_list_all['job_sub_name']
</a>";
} // Show if recordset not empty

elseif ($totalRows_proj_list_all['job_detail'] == 1) { // do not show if recordset empty
echo "<strong>$row_proj_list_all['job_name']; </strong><br />
$row_proj_list_all['job_sub_name'];?
</a>";

} // do not show if recordset empty?>

Thanks,
Alex

eelixduppy

8:06 pm on Feb 13, 2007 (gmt 0)



Welcome to WebmasterWorld, Alex!

Try something like this. You cannot have array values within a string like you do.


<?php
if($totalRows_proj_list_all['job_detail'] == 0) {
echo '<a href="proj_detail.php?job_id='.$row_proj_list_all['job_id'].'"><strong>' .$row_proj_list_all['job_name'].'</strong><br />'.$row_proj_list_all['job_sub_name'].'</a>';
}
else if($totalRows_proj_list_all['job_detail'] == 1) {
echo '<strong>'.$row_proj_list_all['job_name'].'</strong><br />'.$row_proj_list_all['job_sub_name'];
}
?>

For reference, you should take a quick read of Strings Documentation [us3.php.net].

Good luck! :)

sned

9:51 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



You can also do this:

echo "<strong>${row_proj_list_all['job_name']}</strong><br /> ${row_proj_list_all['job_sub_name']}
</a>";

(note the {} - I don't normally do this, I think it makes the code harder to read, but it is a nice shortcut in some situations)

sned

10:37 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



Oops, realized I put the $ in the wrong spot:

${row_proj_list_all['job_name']} should be {$row_proj_list_all['job_name']}