0

我有一个通过包装数据库进行搜索的搜索表单。一切正常,花花公子,当提交搜索时,我会在带有图片的样式框中显示的不同页面上获得返回结果。但不幸的是,它们似乎一个接一个地显示在彼此的下方。虽然他们回来很好,我得到了正确的结果。我希望能够彼此相邻显示三个,然后他们转到下一行并再显示三个,依此类推,直到我用完结果。

这是PHP:

<?php
            $con = mysql_connect ("localhost", "horizon1", "D2j616H5O@Lw");
                   mysql_select_db ("horizon1_delyn", $con);

            if (!$con)
                { 
                    die ("Could not connect: " . mysql_error());
                }

            $descrip = mysql_real_escape_string($_POST['descrip']); 
            $depth   = mysql_real_escape_string($_POST['depth']);
            $varWidth = mysql_real_escape_string($_POST['traywidth']);
            $varHeight= mysql_real_escape_string($_POST['trayheight']);
            $varRange = mysql_real_escape_string($_POST['trayrange']);
            $varType  = mysql_real_escape_string($_POST['traytype']);
            $varShape = mysql_real_escape_string($_POST['trayshape']);
            $varImage = mysql_real_escape_string($_POST['imagename']);

            if (isset($varHeight) && !empty($varHeight)) {
                    $low  = ($varHeight."00");
                    $high = ($varHeight."99");
                } else {
                    $low  = ("000");
                    $high = ("999");
                }

            if (isset($varWidth) && !empty($varWidth)) {
                    $min  = ($varWidth."00");
                    $max = ($varWidth."99");
                } else {
                    $min  = ("000");
                    $max = ("999");
                }   


            $sql = "SELECT * FROM range WHERE 
                        description LIKE '%".$descrip."%'  
                    AND trayrange   LIKE '%".$varRange."%' 
                    AND traytype    LIKE '%".$varType."%' 
                    AND trayshape   LIKE '%".$varShape."%'
                    AND traywidth   BETWEEN '".$min."'  AND '".$max."' 
                    AND trayheight  BETWEEN '".$low."' AND '".$high."' ";


                $r_query = mysql_query($sql);  

                while ($row = mysql_fetch_array($r_query)) 
                    { 
                        echo '<div id="results">';
                        echo '<p class="image">
                                <img src="   '. $row['imagename'] . '" width="150" length="80"> 
                                    </p>';
                        echo '<div id="table"><br />
                                <strong> Tool Code: </strong>  '. $row['toolcode'];
                        echo '<br /><strong> Description: </strong> '. $row['description']; 
                        echo '<br /><strong> Tray range: </strong> '. $row['trayrange']; 
                        echo '<br /><strong> Tray type:  </strong> '. $row['traytype'];
                        echo '<br /><strong> Tray size:  </strong> '. $row['traysize']; 
                        echo '<br /><strong> Tray shape: </strong> '. $row['trayshape'] . '</div>' . '<br />';
                        echo '<a href="enquire.html">Enquiry Page</a> <br />' . 
                             '<a href="packingtest.html">Back to Search</a>';
                        echo '</div>' . '<br />';
                    }
                if (mysql_num_rows($r_query) <= 0){
                    echo 'No results match your search, please try again';
               }
        ?>

这是CSS:

   <style>
 #boxes {
padding: 10px;
margin-top: 20px;
margin: 10px;
float: left;
display: block;
}
 #results {
width: 212px;
    padding: 5px;
    background: #E8CF24;
display: block;
    overflow:auto;

font-family: Verdana, Geneva, sans-serif;
font-size: 11px;
font-color: #FFF;

border: 2px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;

-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
 #table {
margin-top: 10px;
width: 200px;
    padding: 3px;
    background: #FFF;
display: block;
    overflow:auto;

border: 2px solid #cccccc;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;

-moz-box-shadow: 2px 2px 2px #cccccc;
-webkit-box-shadow: 2px 2px 2px #cccccc;
box-shadow: 2px 2px 2px #cccccc;
}
 .image {
margin-left: 28px;
margin-bottom: 0px;
margin-top: 5px;
}
 a:link {
color: #000423;
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
}
 </style>

我尝试使用 CSS 对其进行编辑,但我可以更改位置和填充、边距等。但我无法让它们彼此对齐。

有谁能帮忙吗?提前致谢 :)

4

1 回答 1

-1

在您的 css 中将其添加到您的 #results 选择器。

#results {
   float:left
}

编辑:对不起,这不是正确的答案。删除上面的代码并查看下面的代码。

用下面的代码替换 while 循环。

编辑:不要忘记初始化 $count 变量。($count = 0;) 只需复制粘贴代码,它应该适合你。

   $count = 0;
   while ($row = mysql_fetch_array($r_query)) 
    { 

        $t = $count%3;
        echo ($t==2) ?  '<div id="results">' : '<div id="results" style="float:left">';

        echo '<p class="image">
                <img src="   '. $row['imagename'] . '" width="150" length="80"> 
                    </p>';
        echo '<div id="table"><br />
                <strong> Tool Code: </strong>  '. $row['toolcode'];
        echo '<br /><strong> Description: </strong> '. $row['description']; 
        echo '<br /><strong> Tray range: </strong> '. $row['trayrange']; 
        echo '<br /><strong> Tray type:  </strong> '. $row['traytype'];
        echo '<br /><strong> Tray size:  </strong> '. $row['traysize']; 
        echo '<br /><strong> Tray shape: </strong> '. $row['trayshape'] . '</div>' . '<br />';
        echo '<a href="enquire.html">Enquiry Page</a> <br />' . 
             '<a href="packingtest.html">Back to Search</a>';
        echo '</div>';

        $count++;
    }

这就是我得到的。我没有使用css文件。

在此处输入图像描述

于 2012-10-24T11:09:57.147 回答