2013-02-11 76 views
0

我想建立一个基于数据库结果的动态jQuery移动列表视图。我有以下代码:JQUERY移动数据库结果检索列表视图

<script type="text/javascript">// <![CDATA[ 
$(document).ready(function() { 
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh 
setInterval(function() { 
$('#results').load('./Display.php?id=100'); 
}, 3000); // the "3000" here refers to the time to refresh the div. it is in milliseconds. 
}); 
// ]]></script> 

<div id="results"></div>

有Display.php的while循环

while($row = mysql_fetch_array($query)) { 
    echo "{$row['title']} 
    {$row['message']} 
    {$row['datetime']} 
    </br> 
    ";    
} 

目前这只是输出标题,消息和日期时间上.html和php页面,但我想用于:

<ul data-role="listview" data-inset="true"> 
      <li><a href="index.html"> 
       <h3>Stephen Weber</h3> 
       <p><strong>You've been invited to a meeting at Filament Group in Boston, MA</strong></p> 
       <p>Hey Stephen, if you're available at 10am tomorrow, we've got a meeting with the jQuery team.</p> 
       <p class="ui-li-aside"><strong>6:24</strong>PM</p> 
      </a></li> 
</ul> 

我已经尝试了很多方法来使这个工作,但它似乎并没有,我已经清除了while循环代码,所以它的基本问题。有没有人设法做到这一点?通常我会通过foreach运行<li></li>,但这是不同的。任何帮助将不胜感激。

回答

0

既然你正在建立一个listview,你的结果div应该是一个listview ...不只是一个div。 所以我建议你把

<ul data-role="listview" data-inset="true" id="results"> 
</ul> 

,而不是你

<div id="results"></div> 

只是个开始...... 那么你的PHP应该呼应UL的内容。我的意思是这样的:

echo '<li><h3>'.$row['title'].'</h3><p><strong>'.$row['message'].'</strong></p></li>';  

我没有测试它,但你应该。

+0

感谢您的回复,但我在本月前排序:D – Daniel 2013-07-11 08:10:30

相关问题