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

标签 php html mysql sql dom

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

<!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/

相关文章:

php - PHP 中的 shell_exec 返回空字符串

python - 加快 MySQL 更新/插入语句

mysql - 展示 SQL - NoSQL 环境优势的最佳方法是什么?

php - JSON_NUMERIC_CHECK 和电话号码

php - Json key 缺少 google photos api 中的刷新 token 字段

php - 正则表达式从最后一个开始提取所有特定长度的数字

sql - 在没有子查询的 MySQL 中,优先于 GROUP BY 的 ORDER BY

html - 更改电子邮件模板中的字体系列

javascript 在超时时隐藏下拉菜单

asp.net - 标题属性 - 对于使网页可访问有用吗?