简体   繁体   English

如何显示数据库中彼此相邻的列表项?

[英]How to display list items from database next to each other?

I have the following page, where a list of attractions from my "attraction" table are displayed: 我在以下页面上显示“吸引力”表中的景点列表:

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

Right now the items from my database are displayed as a list one under the other, as expacted. 现在,按照我的说法,我数据库中的项目显示为一个列表,一个显示在另一个列表之下。 How can I maake it so that it displays two items from the list next to each other, and under them another two and so on? 我该如何制作它,使其在列表中彼此相邻显示两个项目,并在其下方显示另外两个项目,依此类推? Is there any CSS I can use for that? 我可以使用任何CSS吗? Thanks 谢谢

why dont you target the even lists using the css nth child property to target the odd lists add something like this to your css 为什么不使用css nth子属性将偶数列表作为目标,将奇数列表作为目标

ul.submenu {

}
ul.submenu li {

    display: inline;
    height: 50px;

    margin: 20px;
    float: left;
}

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

hope this works i have updated the fiddle here customise to you usage jsfiddle 希望这项工作我更新了小提琴在这里自定义为您使用jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM