我有一个mysqli数据库和表单,允许我存储ID,名称和照片。照片的路径设置为"图像"服务器上的文件夹。我有一个可以
的查询SELECT * FROM images WHERE name = $ pagetitle。
这在javascript幻灯片之外非常好用。当我在javascript中放置一个php命令来查找要显示的图像时,js只显示1个图像,而不是所有图像。
任何帮助都将不胜感激,谢谢。
有问题的代码部分如下......
<!-- Image Slide Show Start -->
<div style="display: flex; justify-content: center;">
<img align="middle" src="" name="slide" border=0 width=300 height=375>
<script>
<?php
require('dbconnect.php');
$data = mysql_query("SELECT * FROM images WHERE name= '$pagetitle'");
$image = mysql_fetch_array( $data );
?>
//configure the paths of the images, plus corresponding target links
slideshowimages("<?php echo "/images/".$image['photo'] . ""?>")
//configure the speed of the slideshow, in miliseconds
var slideshowspeed=2000
var whichlink=0
var whichimage=0
function slideit(){
if (!document.images)
return
document.images.slide.src=slideimages[whichimage].src
whichlink=whichimage
if (whichimage<slideimages.length-1)
whichimage++
else
whichimage=0
setTimeout("slideit()",slideshowspeed)
}
slideit()
</script> </div><br><br>
<!-- Image Slide Show End -->
&#13;
答案 0 :(得分:2)
您的更新查询存在语法错误,在字段之间使用,
,您还必须在2 '
中包含字符串:
$query = "UPDATE page_content SET PageTitle='$pageTitle',
PageContent='$PageContent', PageContent2='$PageContent2' WHERE PageId='$PageId'";
答案 1 :(得分:1)
您在查询中的变量和<ul class="slider-thumbs">
<li class="reason-item"><a>Item 1</a></li>
<li class="reason-item"><a class="selected">Item 2</a></li>
<li class="reason-item"><a>Item 3</a></li>
<li class="reason-item"><a>Item 4</a></li>
<li class="reason-item"><a>Item 5</a></li>
</ul>
字段之间错过了,
。
''
OR
$sql = "UPDATE page_content SET PageTitle='$pageTitle',
PageContent='$PageContent', PageContent2='$PageContent2'
WHERE PageId='$PageId'";
// check query executed successfully or get error
$result = mysqli_query($conn,$sql) or die(mysqli_error($conn));
希望它会对你有所帮助:)。
答案 2 :(得分:0)
试试这个:
$sql = "SELECT * FROM images WHERE name= '$pagetitle'";
$result = $conn->query($sql);
$directory = '';
while( $image = $result->fetch_assoc() )
$directory .= ($directory != '' ? "," : '') . ('"/images/'.$image["photo"] . '"');
// Check if it was successfull
if($directory != '') {
// if there are images for this page, run the javascript
?><script>
//configure the paths of the images, plus corresponding target links
slideshowimages(<?php print $directory ?>)