-1

嗨,它只是不会返回我之前遇到过这个问题的所有图片,而且我真的不知道每当我将代码放在类文件中时是什么原因导致它

<?php
class get_pic{

function thumb($id){
$piclist = '';
     if (isset($_GET['id'])) {

    $id = preg_replace('#[^0-9]#i', '', $_GET['id']); 
    // Use this var to check to see if this ID exists, if yes then get the product 
    // details, if no then exit this script and give message why
    $sql = mysql_query("SELECT * FROM productpic WHERE id='$id' ");
    $productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
        // get all the product details
        while($row = mysql_fetch_array($sql)){
                 $path1 = $row["path1"];
                 $piclist ='<li id="thumb"><img id="thumb" style=" position:relative; border:#666 1px solid;  "  src="'.$path1.'" alt="' . $id . '" width="120" height="160" border="1" /></li>';
              } 

          }     

         }
          return $piclist;
       }
    }   
?>
4

2 回答 2

0

$piclist只有最后一个值。您应该连接字符串。

进行以下更改:

...
if ($productCount > 0) {
  while($row = mysql_fetch_array($sql)) {
    $piclist .= '<li>...';
于 2013-10-08T19:32:45.397 回答
0

改变这个:

$piclist = '';
...
$piclist ='<li id="thumb"><img id="thumb" style=" position:relative; border:#666 1px solid;  "  src="'.$path1.'" alt="' . $id . '" width="120" height="160" border="1" /></li>';

...这可能会解决它:

$piclist = array();
...
$piclist[] ='<li id="thumb"><img id="thumb" style=" position:relative; border:#666 1px solid;  "  src="'.$path1.'" alt="' . $id . '" width="120" height="160" border="1" /></li>';
于 2013-10-08T19:34:18.140 回答