开发者

mysql results in a given content

I have a MySQL result set that I am appending with HTML and need the all the results to come out as single string. Basically I need to push all my results to a single variable(that isn't and array) and be able to json encode them, and echo them back to the browser as a single string. In the current context it only returns the first last row. Like I said though, I don't need an array, just a single string.

while($r = mysql_fetch_array($result)) {    
$menu_id = $r['id'];
$name = $r['name'];

$page_content = '<ul><li class="menu_head_separator">&hellip;&hellip;&hellip;&hellip;&hellip;</li>'.'<li class="开发者_开发知识库panel_sub_link">
  <a class="nav_anchor nav_anchor_staff_'.$menu_id .'" href="javascript:getStaffDetail('.$menu_id .');"   onclick="anchorSubNav("staff",'.$menu_id .');">'.$name.'<br/><span class="staff_occupation">'.$position.'</span></a></li>';


First of all, you need to close "}" bracket in your loop. Then, for appending t variabled you need to use ".=" instead of "=". And last, better json encode an array, not HTML.


Replace $page_content = ''; by $page_content .= ''; to add a string to another. Otherwise only the last set string will be returned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜