gpt4 book ai didi

php - 设置多个 while 循环结果的样式,让它们彼此相邻?

转载 作者:行者123 更新时间:2023-11-28 15:35:41 25 4
gpt4 key购买 nike

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

这是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 对其进行编辑,但我可以更改位置和填充、边距等。但我无法让它们彼此对齐。

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

最佳答案

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

#results {
float:left
}

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

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

编辑:不要忘记初始化 $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 文件。

enter image description here

关于php - 设置多个 while 循环结果的样式,让它们彼此相邻?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13047909/

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