Forum Moderators: coopster

Message Too Old, No Replies

Correct syntax

Correct syntax for the code

         

kkonline

11:52 am on Mar 8, 2008 (gmt 0)

10+ Year Member



<td><img src='img/online.gif'></td>
<td><?php echo "<a href = \"#\" onclick = \"fnCheck(".$row['user_name']."\")>"<a/>. $row['user_name']?></td>

Kindly help me write this above code

dreamcatcher

12:15 pm on Mar 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<td><?php echo "<a href = \"#\" onclick = \"fnCheck(".$row['user_name']."\")>".$row['user_name']."</a>"; ?></td>

Should be ok I think. I assume you wanted the username in the a tags?

I would do it in single quotes personally:

<td><?php echo '<a href = "#" onclick = "fnCheck('.$row['user_name'].'")>'.$row['user_name'].'</a>'; ?></td>

dc

kkonline

12:31 pm on Mar 8, 2008 (gmt 0)

10+ Year Member



hi dreamcatcher,
thaks for your help.
I have a doubt '.$row['user_name'].' what is the logic of using single quotes around this variable as the whole part is in double quotes?

kkonline

12:34 pm on Mar 8, 2008 (gmt 0)

10+ Year Member



how do i decide when to use single or double quotes are there any rules for using it?

web master genius

1:55 pm on Mar 8, 2008 (gmt 0)

10+ Year Member



how do i decide when to use single or double quotes are there any rules for using it?

Single/Double quote difference: eg:

<?php
$var = '$var';
$vara = 'ha';
$text = "$vara";
echo $text; //Outputs ha
echo $vara; //Output ha
echo $var; /* Outputs $var as it was in single quotes. php does no process variables in single quotes. So $var = '$tex la' outputs $tex la. But, $var = "$tex la" outputs the contents of $tex and then la. */
?>

have you understood? lookup somewhere on the net!
bye,
webmastergenius

jatar_k

2:27 pm on Mar 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



take a look at this for single/double quote usage
[php.net...]