gpt4 book ai didi

php - 如何相邻显示数据库中的列表项?

转载 作者:行者123 更新时间:2023-11-30 00:19:52 25 4
gpt4 key购买 nike

我有以下页面,其中显示了“景点”表中的景点列表:

<!DOCTYPE HTML>
<html>
<body>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="jquery.imagemapster.js"></script>
<link rel="stylesheet" type="text/css" href="css.css" />



<title>VisitBulgaria</title>
</head>



<div class="banner">




<a href="home.html">
<img src="images/banner.png" alt="kimtech" border="0" height="150" width="500" /></a>

<div class="namelog">


<?php

if (isset($_SESSION['ID'])){


echo $Forename." ".$LastName;
echo '<a href="logout.php">Logout</a> &sol; ';
echo '<a href="userpage.html">Account</a>';

}

else {

if (!isset($_SESSION['ID'])){


echo '<a href="login.php">Log In</a> &sol; ';
echo '<a href="register.php">Register</a>';

}
}
?>
</div>




</div>

<div class="center">
<div class="menu">


<ul>
<li ><a href="home.html">Home</a></li>
<li class='active'><a href="attractions.html">Attractions</a>


<ul class="sub-menu">
<li>
<a href="historyv.html">Historical Villages</a>
</li>
<li>
<a href="nature.html">Nature</a>
</li>
<li>
<a href="sr.html">Seaside Resorts </a>
</li>
<li>
<a href="wr.html">Winter Resorts </a>
</li>
<li>
<a href="atimes.html">Ancient Times</a>
</li>

</ul>


</li>
<li><a href="traditions.html">Traditions</a></li>
<li><a href="pictures.html">Pictures</a></li>
<li><a href="about.html">About Us</a></li>






</ul>

</div>










<div class="center1">


<?php

if (!$link = mysql_connect('localhost', 'root', '')) {
echo 'Could not connect to mysql';
exit;
}

if (!mysql_select_db(')) {
echo 'Could not select database';
exit;
}

$sql = "SELECT `AttractionID`,`Name`, `Location`, `Description`, `Airport`, `imglink`, `imglink2` FROM `attractions` WHERE `Category`='HistV'";
$result = mysql_query($sql, $link);

if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}




while ($row = mysql_fetch_assoc($result)) {

echo "<a href='attraction.php?village=" . $row['AttractionID'] . "'>" . "<br />" .
$row['Name'] .
"<br />" .

"<img src='" . $row['imglink2'] . "' height='130' width='150'>

</a>";

}
mysql_free_result($result);

?>







</div>







</div>

</body>
</html>

现在,我的数据库中的项目按照预期显示为一个列表。我怎样才能使它显示列表中彼此相邻的两个项目,并在它们下面显示另外两个项目,依此类推?我可以使用任何 CSS 来实现这一点吗?谢谢

最佳答案

为什么不使用 css nth 子属性来定位偶数列表来定位奇数列表,将这样的内容添加到您的 css

ul.submenu {

}
ul.submenu li {

display: inline;
height: 50px;

margin: 20px;
float: left;
}

ul.submenu li:nth-child(odd) {
color: #F00;
clear: left;
}

希望这有效,我已经更新了这里的 fiddle ,根据您的用法定制jsfiddle

关于php - 如何相邻显示数据库中的列表项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23324722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com