这是我的代码,设置了样式,现在就是不知道要怎样把图片读出,图片的名字和路径在数据库中,<img>中src的值要怎么写,数据库查询要怎么查询?求指点
<?php $query=mysql_query("select * from tb_tpsc where type='达人收藏' order by id desc ",$conn);
while($row=mysql_fetch_array($query)) 
  {
$path=$row['tpmc'];
$name=$row['name'];
 ?>
<ul id="products"> 
<li><a href="#"><img src="$path" alt="" width="100" 
height="75"/></a> 
<span><a href="#"><?php echo"$name";?></a></span> 
</li> 
<li><a href="#"><img src="$path" alt="" width="100" 
height="75"/></a><span><a href="#"><?php echo"$name";?></a></span> 
</li> 
<li><a href="#"><img src="$path" alt="" width="100" 
height="75"/></a> 
<span><a href="#"><?php echo"$name";?></a></span> 
</li> 
</ul> 
<?php };?>

解决方案 »

  1.   


    <ul id="products"><?php $query=mysql_query("select * from tb_tpsc where type='达人收藏' order by id desc limit 0,3 ",$conn );
    while($row=mysql_fetch_array($query))  
      {
    $path=$row['tpmc'];
    $name=$row['name'];
    echo <<<eof
       <li> <a href="#"><img src="{$path}" alt="{$name}" width="100" height="75" /></a>  
       <span><a href="#">{$name}</a></span> </li>
    eof;
     }
     ?>
    </ul>http://www.php.net/manual/zh/language.types.string.php
      

  2.   

    通过css设置,设置li的宽度和float为left,3个li宽度加起来刚好是外面div的宽度,会自动换行的。
    置于php计算换行,这么个思路:
    $i = 1;
    while ($row = mysql_fetch_array($query)) {
        echo $row['src'];
        // some other code
        $i++;
        if ($i % 3 == 0) {
        echo '<br />';
        }
    }