This is a discussion on Quotes not appearing after variables within the PHP Language forums, part of the PHP Programming Forums category; I have this block of code.... while($i <= $count) { $final = mysql_fetch_row($result); $blocknamelist .= "<a style = \"cursor: ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have this block of code....
while($i <= $count) { $final = mysql_fetch_row($result); $blocknamelist .= "<a style = \"cursor: pointer\" onmouseout = \"clear_desc()\" "; $blocknamelist .= "onclick = delete_block(\"$final[1]\",\"$final[2]\") onmouseover = display_desc(\"$final[2]\") >"; $blocknamelist .= "<font color = \"red\">X</font></a> <br />\n"; $i++; } This is the output: <a style =" cursor: pointer" onmouseout =" clear_desc()" onclick = delete_block("QL","Quick Links) onmouseover = display_desc("Quick Links) ><font color =" red">X</font></a> <br /> <a style =" cursor: pointer" onmouseout =" clear_desc()" onclick = delete_block("AD","Admin Menu) onmouseover = display_desc("Admin Menu) ><font color =" red">X</font></a> <br /> As you can see, around Quick Links the quote sequence never shows up as well as around Admin Menu. I can't figure this out. I have tried these sequences: 'text "' . $variable . '" more text'; "text \"". $variable . "\" more text"; <<<EOD Text "$variable" more text EOD; Among as many other patterns I could think of. What I don't understand is. If I do this: $test = '"' . $variable . '"'; it works exactly how I want it to act, as well as the same with every above pattern I have tried. it is only when I try and get it to print in the above manner within the javascript function calls that I get a problem. Do the parenthesis in the string effect it some how? I've never seen it do this before, so I am bamboozled. Any and all help is appreciated. |
|
|||
|
Well I finally got it today. I tried and still try the single quotes
and it fails saying "Unterminated String Literal". Anyways what I ended up having to do is just add a single quote around the entire javascript function call. I am really baffled as to why that code worked for you though :-\. Anyways here is my revised code. $blocknamelist .= "<a style = 'cursor: pointer;' onmouseout = 'clear_desc()' "; $blocknamelist .= "onclick = 'delete_block(\"$final[1]\",\"$final[2]\")' onmouseover = 'display_desc(\"Delete $final[2] Block\")' >"; $blocknamelist .= "<font color = 'red'>X</font></a> \n"; I have no idea why adding those single quotes made any effect on it displaying the double quotes, it still makes no sense to me and I would be really intrigued to see an explanation of this. Especially when a variable can hold the information fine, but as soon as I try to concantenate<sp?> it messes everything all up. Very strange behavior indeed. But thank you for your responses. Josh |
|
|||
|
Well I finally got it today. I tried and still try the single quotes
and it fails saying "Unterminated String Literal". Anyways what I ended up having to do is just add a single quote around the entire javascript function call. I am really baffled as to why that code worked for you though :-\. Anyways here is my revised code. $blocknamelist .= "<a style = 'cursor: pointer;' onmouseout = 'clear_desc()' "; $blocknamelist .= "onclick = 'delete_block(\"$final[1]\",\"$final[2]\")' onmouseover = 'display_desc(\"Delete $final[2] Block\")' >"; $blocknamelist .= "<font color = 'red'>X</font></a> \n"; I have no idea why adding those single quotes made any effect on it displaying the double quotes, it still makes no sense to me and I would be really intrigued to see an explanation of this. Especially when a variable can hold the information fine, but as soon as I try to concantenate<sp?> it messes everything all up. Very strange behavior indeed. But thank you for your responses. Josh |
|
|||
|
.oO(Josh)
>Well I finally got it today. I tried and still try the single quotes >and it fails saying "Unterminated String Literal". What PHP version? Can you strip it down to a short line of code (as short as possible) that still shows the error? >I have no idea why adding those single quotes made any effect on it >displaying the double quotes, Quotes are necessary because onXXX are attributes in HTML, their values should be single- or double-quoted. But I have no idea how or why this affects PHP. >it still makes no sense to me and I >would be really intrigued to see an explanation of this. Especially >when a variable can hold the information fine, but as soon as I try to >concantenate<sp?> it messes everything all up. concatenate Your (old) code works on my system (PHP 5.0.0 and 4.3.3). And so does the following: $blocknamelist = "<a style = 'cursor: pointer;' onmouseout = 'clear_desc()' onclick = 'delete_block(\"$final[1]\",\"$final[2]\")' onmouseover = 'display_desc(\"Delete $final[2] Block\")' ><font color = 'red'>X</font></a> \n"; Micha |