以两行显示搜索结果

时间:2012-07-03 11:51:44

标签: php mysql row

我正在制作一个网页,我将其添加为搜索引擎。以下是结果页面中的代码。

    $term = $_POST['term'];

    $sql = mysql_query("select * from artists2 where Fname like '%$term%' or Genre like '%$term%' or Specialty like '%$term%' order by Fname");

while ($row = mysql_fetch_array($sql)){
    echo '<table width="550" border="0" cellspacing="0" cellpadding="0">';
  echo '<tr>';
  echo '<td width="550" height="200"><img src="'.$row['Bio']. '" alt="" width="150" height="200"></td>';
  echo '</tr>';
  echo '<tr>';
  echo '<td width="550" height="30">Name: '.$row['Fname'].'</td>';
  echo '</tr>';
  echo '<tr>';
  echo '<td width="550" height="30">Genre: '.$row['Genre'].'</td>';
  echo '</tr>';
  echo '<tr>';
  echo '<td width="550" height="30">Specialty: '.$row['Specialty'].'</td>';
  echo '</tr>';
  echo '<br/>';
  echo '<br/>';
  echo '<br/>';
echo '</table>';
    }
?>

我希望结果显示为两行,而不是现在显示的一行。 每个结果还有一张图片和3行文字。我希望文本显示在图片的右侧。不在现在的图片下方。

更新1

Dainis你的代码非常有帮助。如此贴近我的需要。 你的代码给了我这个: enter image description here

但我需要这样的东西:

enter image description here

3 个答案:

答案 0 :(得分:1)

哇。那是一些严重过时的HTML代码。您应该从不使用table进行布局,就像您正在进行的那样。现在有更好的解决这些布局的方法。

这是一个使用CSS进行布局的JSFiddle。小提琴中的HTML是语义含义,它准确地表示您向访问者显示的数据(有或没有视觉)以及搜索引擎:

http://jsfiddle.net/CgbQH/

正如您所看到的,搜索结果列表就是这样;一个列表。每个结果都有一个图像和一个dl(有些人可能认为dl不是键/值对的正确选择)。然后使用CSS使标记以您想要的方式呈现。

此外,永远不会永远将用户输入(您的$_POST['term'])直接粘贴到这样的查询中。你没听说过小鲍比桌子发生了什么事吗? http://xkcd.com/327/

编辑:我使用column-count将列表渲染为两列。 column-count仅适用于现代浏览器,因此,如果您必须支持IE,则可以将每个li设置为float: left; width: 50%。但是,这会使项目的顺序与column-count不同。

答案 1 :(得分:0)

您需要删除部分代码

while ($row = mysql_fetch_array($sql))
{
  echo '<table width="550" border="0" cellspacing="0" cellpadding="0">';
  echo '<tr>';
  echo '<td width="550" height="200" valign="top"><img src="'.$row['Bio']. '" alt="" width="150" height="200"></td>';
  echo '</tr>';
  echo '<tr>';
  echo '<td width="550" height="30" valign="top">';
  echo 'Name: '.$row['Fname'].'<br />';
  echo 'Genre: '.$row['Genre'].'<br />';
  echo 'Specialty: '.$row['Specialty'];
  echo '</td>';
  echo '</tr>';
  echo '</table>';
  echo '<br/>';
  echo '<br/>';
  echo '<br/>';
}

答案 2 :(得分:0)

您希望它看起来如何?喜欢这个?

enter image description here

然后代码将是这样的:

while ($row = mysql_fetch_array($sql)){
echo '<table width="550" border="0" cellspacing="0" cellpadding="0" style="width: 40%; float: left;">';
  echo '<tr>';
  echo '<td width="550" height="200" align="left" valign="top"><img src="'.$row['Bio']. '" alt="" width="150" height="200"></td>';
  echo '<td width="550" height="30" align="left" valign="top">';
  echo '<p>Name: '.$row['Fname'].'</p>';
  echo '<p>Genre: '.$row['Genre'].'</p>';
  echo '<p>Specialty: '.$row['Specialty'].'</p>';
  echo '</td>';
  echo '</tr>';
echo '</table>';
}
相关问题