[英]what is making this php code functioning that is outputing HTML?
I'm trying to output a button using PHP but I cant seem to get the '
and "
correctly. 我正在尝试使用PHP输出按钮,但是我似乎无法正确获取
'
和"
。
This is the output I should be getting from the PHP code below: 这是我应该从下面的PHP代码获得的输出:
<button class="button button1" onclick="buttonTest(99.16918,-82.9191)"> Lithuania </button>
This is my code: 这是我的代码:
foreach ($getClasses as $row){
echo '<button class="button button1" onclick="buttonTest(', $row->BUILDING_Latitude ,',',$row->BUILDING_Longtitude,)>', $row->COURSE_Title,'</button>';
}
how do i get php to output this html code above i get an error 我如何获取php以输出上述html代码,但出现错误
syntax error, unexpected '>' (48) : eval()'d code
syntax error, unexpected ')', expecting ',' or ';' (48) : eval()'d code
Update 更新资料
Also, please advice me the best way to rewrite this, so that these kind of issues do not occur in the future. 另外,请给我建议最好的重写方法,以免将来发生此类问题。
You missed the '
here: 您错过了
'
这里:
tude, ')">', $ro
//----^-^
Full code: 完整代码:
echo '<button class="button button1" onclick="buttonTest(', $row->BUILDING_Latitude ,',',$row->BUILDING_Longtitude, ')">', $row->COURSE_Title,'</button>';
//------------------------------------------------------------------------------------------------------------------^-^
I would really write this way: 我真的会这样写:
<?php
foreach ($getClasses as $row) {
echo "<button class=\"button button1\" onclick=\"buttonTest({$row->BUILDING_Latitude}, {$row->BUILDING_Longtitude})\">{$row->COURSE_Title}</button>";
}
Or even better: 甚至更好:
<?php
foreach ($getClasses as $row) {
$lat = $row->BUILDING_Latitude;
$lon = $row->BUILDING_Longtitude;
$course = $row->COURSE_Title;
echo "<button class=\"button button1\" onclick=\"buttonTest($lat, $lon)\">$course</button>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.