我正在尝试从我的数据库和文本中检索图像以将其放在网站上。这是我的代码:
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("gamelogin");
$sql = mysql_query("SELECT * FROM prezentacja ORDER BY id ASC");
$img = mysql_query("SELECT * FROM img");
$id = 'id';
$text = 'text';
$rows = mysql_fetch_assoc($sql);
$images = mysql_fetch_assoc($img);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Game Project</title>
<link rel="stylesheet" href="css/base.css" />
<link rel="stylesheet" type="text/css" href="css/presentation.css">
<script src="js/jquery-1.9.1.min.js"></script>
<script src="js/jquery.cslide.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#cslide-slides").cslide();
});
</script>
</head>
<body>
<div id="main">
<div class="container">
<section id="cslide-slides" class="cslide-slides-master clearfix">
<div class="cslide-prev-next clearfix">
<span class="cslide-list"><a href="index_front.php">Lista gier</a></span>
<span class="cslide-prev">Poprzedni</span>
<span class="cslide-skip"><a href="main.html">Pomiń</a></span>
<span class="cslide-next">Następny</span>
</div>
<div class="cslide-slides-container clearfix">
<div class="cslide-slide">
<p>
<?php if($rows['id'] == 1) echo $rows['text']; ?>
</p>
<?php if($images['id'] == 1) echo "<div class=\"slajd_1\">"; ?> <img src="<?php echo $images["img"]; ?>"> <?php echo "</div>"; ?>
</div>
<div class="cslide-slide">
<p>
<?php if($rows['id'] == 1) echo $rows['text']; ?>
</p>
<?php if($images['id'] == 1) echo "<div class=\"slajd_2\">"; ?> <img src="<?php echo $images["img"]; ?>"> <?php echo "</div>"; ?>
</div>
<div class="cslide-slide">
<h2>This is slide 3</h2>
<p></p>
</div>
<div class="cslide-slide">
<h2>This is slide 4</h2>
<p></p>
</div>
<div class="cslide-slide">
<h2>This is slide 5</h2>
<p></p>
</div>
</div>
</section>
<!-- /sliding content section -->
</div>
</div>
<!-- #main -->
</body>
</html>
我正在尝试使用PHP在html中创建某种演示文稿,以便从MySql中检索每张幻灯片和图像的文本。
这部分代码完美无缺,因为我希望它能够工作。如果id = 1,我会得到图片和文字。
但是当我试图获取id = 2的图像和文本时,它会破坏所有网站并显示id = 1的图像和文本。
<div class="cslide-slide">
<p>
<?php if($rows['id'] == 2) echo $rows['text']; ?>
</p>
<?php if($images['id'] == 2) echo "<div class=\"slajd_2\">"; ?>
<img src="<?php echo $images["img"]; ?>"> <?php echo "</div>"; ?>
</div>
请你看看这个并帮助我弄清楚它出了什么问题?我在做错了吗?