我有一个电影报价网站。我有一些PHP和javascript是由我付钱的人写的,我对PHP或javascript一无所知。代码从数据库中抓取随机引用并在网站上显示它。它每10秒更改一次报价。我在数据库中也有一个名为link的字段,其中包含引用来自的电影页面的链接。我想将引用转换为该电影页面的链接。我很感激如何更改代码来提供帮助。
randomquote.php文件:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
header("Content-Type: text/xml; charset=utf-8");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
$sql = "SELECT COUNT(*) FROM quotes";
$result = mysqli_query($conn,$sql);
$rows=$result->fetch_row();
//$rows = mysqli_num_rows($result);
$rndm=rand(1,$rows[0]);
$sql = "SELECT quote FROM quotes where id='".$rndm."' Limit 1";
$result = mysqli_query($conn,$sql);
if($result)
{
$row = mysqli_fetch_assoc($result);
$xml='<root>';
$xml.='<qoute>'.htmlspecialchars($row['quote']).'</qoute>';
$xml.='</root>';
echo $xml;
}
else
{
echo "Not working";
}
mysqli_close($conn);
?>
的javascript:
var qouteobj=createRequestObject();
function getqoute(){
qouteobj.open("GET","/php/randomquote.php",true);
qouteobj.send(null);
qouteobj.onreadystatechange=function(){
if(qouteobj.readyState==4 && qouteobj.status==200)
{
var q_rec=qouteobj.responseText;
if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(q_rec,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(q_rec);
}
var rq=xmlDoc.getElementsByTagName("qoute");
var txt="";
var i;
for (i=0;i<rq.length;i++){
txt=txt + rq[i].childNodes[0].nodeValue + "<br>";
}
document.getElementById('random-quote').innerHTML=txt;
setTimeout('getqoute()',10000);
}
}
}
答案 0 :(得分:0)
<a href="http://www.bestmoviequote.com/movies/gone-with-the-wind.php">"Frankly, my dear, I don't give a damn."</a>
它正确显示页面上的链接。谢谢你的帮助。