从数据库字段中获取链接并使用它来转换另一个我已抓到链接的字段[关闭]

从数据库字段中获取链接并使用它来转换另一个我已抓到链接的字段[关闭]

问题描述:

I have a website of movie quotes. I have some php and javascript that was written by someone I paid, I don't know anything about php or javascript. The code grabs a random quote from a database and displays it on the site. It changes the quote every 10 seconds. I also have a field in the database called link which contains the link to the movie page that quote is from. I want to turn the quote into a link to that movie page. I'd appreciate any help with how to change the code to do this.

the randomquote.php file:

<?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);
}
}
}

I fixed it myself. I simply updated the quote field in the database to include the link. For example:

<a href="http://www.bestmoviequote.com/movies/gone-with-the-wind.php">"Frankly, my dear, I don't give a damn."</a>

It correctly displays the link on the page. Thanks for all your help.