我有一个显示为列表格式的提交表单,我想知道我能做些什么来使列表只显示一定数量的最新提交信息.我正在测试它,目前列表在一个页面上,只显示50多个提交页面很长时间.
<?php
$query='select * from article order by `article`.`time` DESC';
$result=mysql_query($query);
echo '<table width="600px">';
while($row = mysql_fetch_array($result))
{
echo "<td><a href='".$row['url']."'>".$row['title']."</a></td> <td>".$row['description']."</td><td>".$row['type']."</td></tr>";
}
echo '<table>';
?>
Run Code Online (Sandbox Code Playgroud) 该脚本应该检查提交的值是否为Url,但它不会这样做.我对正则表达式并不太熟悉,我的伙伴们为我做了这个旅行.
<script type="text/javascript">// <![CDATA[
window.onload=init;
function init(){
document.forms[0].onsubmit= function (){
var url= document.getElementById("url").value;
var desc= document.getElementById("description").value;
var regex=new RegExp("^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$");
var match=regex.test(url);
if(!match)
{
alert("The URL you entered is not valid");
return false;
}
if(desc.length<10)
{
alert("There must be at least 10 characters in the description");
return false;
}
};
}
// ]]></script>
Run Code Online (Sandbox Code Playgroud)