0
我試圖通過從數據庫中獲取值來生成多個鏈接。 我可以連接到沒有任何問題的數據庫,並且我可以毫無問題地提取變量,但是當我嘗試生成我的html代碼時,一切都變成了亂碼。從javascript生成URL的問題
<script type="text/javascript">
//Generate carousel
var mymovies = "<div id='tumbnailtest' class = 'carousel'><ul><li><a href='watchmovie.php?path=";
for (var i = 1; i < 10; i++){
<?php
//Get movie List
$result = mysql_query("SELECT Title, Filepath, Posterpath FROM movies WHERE ID = $count");
while ($row = mysql_fetch_array($result)) {
//for generating url
$mpath = $row["Filepath"];
$mmname = $row["Title"];
$ppath = $row["Posterpath"];
$count = $count + 1;
}
?>
mymovies += "<li><a href=watchmovie.php?path=<?php echo $mpath;?>"
mymovies += "&mname=<?php echo $mmname;?><img src=<?php echo $ppath;?> width='200' height='300' border='0' style='padding: 0 0px 0 0px;' title='<?php echo $mmname; ?>'></a></li>";
}
mymovies += "</ul></div>";
document.write(mymovies);
</script>
路段端部這樣看
<a href="watchmovie.php?path=<li><a href=watchmovie.php?path=Movies/iRobot.mp4&mname=iRobot<img src=images/iRobot.jpeg width=" 200'="" height="300" border="0" style="padding: 0 0px 0 0px;" title="iRobot"></a>
當應該結束這樣看
<li><a href='watchmovie.php?path=<?php mname ?>&mname=<?php echo $mname;?>' target="_blank"><img id='' src='<?php echo $ppath; ?>' width="200" height="300" border="0" style="padding: 0 0px 0 0px;" title="<?php echo $mname; ?>"></a></li>
哪裏MNAME是iRobot公司當$計數= 1。這哪裏是多餘的<li> < a href = watchmovie.php?path = from?好像我正在將隨機垃圾寫入我的鏈接。
更新文件在這裏。
<?php
//connect to database server
$row;
$dbcnx1 = mysql_connect("localhost", "root", "wouldntyouliketoknow");
if (!$dbcnx1){
echo("<P>Unable to connect to the database server at this time.</P>");
exit();
}
else{
echo("<P>Successfully connected to the database!</P>");
}
//select database
mysql_select_db("movies", $dbcnx1);
if (! @mysql_select_db("movies")) {
echo("<P>Unable to locate the movies database at this time.</P>");
exit();
} else {
echo("<P>Successfully connected to the movies database!</P>");
}
//Get movie List
$count = 1;
?>
<html>
<link rel="stylesheet" type="text/css" href="css/JMyCarousel.css" />
<script type='text/javascript' src="js/jquery.js"></script>
<script type='text/javascript' src='js/scollingcarouselunminified1.js'></script>
<script type="text/javascript">
$(document).ready(function() {
$('#tumbnailtest').scrollingCarousel({
autoScroll: false
});
});
</script>
<?php
$mymovies = "<div id='tumbnailtest' class = 'carousel'><ul>";
for ($i = 1; $i <= 10; i++) {
//Get movie List
$result = mysql_query("SELECT Title, Filepath, Posterpath FROM movies WHERE ID = ".$i);
while ($row = mysql_fetch_array($result)) {
//for generating url
$mpath = $row["Filepath"];
$mmname = $row["Title"];
$ppath = $row["Posterpath"];
}
$mymovies .= "<li><a href='watchmovie.php?path=".$mpath;
$mymovies .= "&mname=".$mmname."'><img src='".$ppath."' width='200' height='300' border='0' style='padding: 0 0px 0 0px;' title='".$mmname."'></a></li>";
}
$mymovies .= "</ul></div>";
echo $mymovies;
?>
</html>
好得多!謝謝!但是, Mr404servererror 2013-03-24 09:20:44
Try again, just edited – aNewStart847 2013-03-24 09:25:27
Awwww yeah! You are the best. – Mr404servererror 2013-03-24 09:29:15