echo sql或显示“no items”

时间:2011-05-18 06:03:37

标签: php sql

需要显示以下内容:

  1. 显示某种面料的所有商品

  2. 如果sql显示中没有可用的结构“无结果”

  3. 代码完全适用于第一点,但不支持第二个功能。 非常感谢帮忙。

    //echo $sql;
    
    $data = "";
    $ii = 0;
    $m = 0;
    while($myrow = mysql_fetch_array($result)){
        $ii++;
        $m++;
        if ($m == 1) $data = $data."<div class=\"page current\" id=\"gallery\">";
        elseif ($ii == 1) $data = $data."<div class=\"page\" id=\"gallery\">";
    
        $data = $data."<a href=\"#\" title=\"".$myrow['name']."\" class=\"show_fabric\" rel=\"".$myrow['id']."\"><img src=\"".$image_directory.$myrow['thumbnail']."\" width=\"100 px\" height=\"100 px\"><div class=\"fb_name\">".$myrow['name']."</div></a>\n";
        if ($ii == 10) {
            $data = $data."</div>";
            $ii = 0;
        }
    }
        if ($ii != 10) {
            $data = $data."</div>";
        }
    
    if (empty($data)) echo "No result";
    else echo $data;
    

3 个答案:

答案 0 :(得分:1)

    if($result && mysql_num_rows($result)>0)
    {
     $data = "";
   $ii = 0;
  $m = 0;
while($myrow = mysql_fetch_array($result)){
    $ii++;
    $m++;
    if ($m == 1) $data = $data."<div class=\"page current\" id=\"gallery\">";
    elseif ($ii == 1) $data = $data."<div class=\"page\" id=\"gallery\">";

    $data = $data."<a href=\"#\" title=\"".$myrow['name']."\" class=\"show_fabric\" rel=\"".$myrow['id']."\"><img src=\"".$image_directory.$myrow['thumbnail']."\" width=\"100 px\" height=\"100 px\"><div class=\"fb_name\">".$myrow['name']."</div></a>\n";
    if ($ii == 10) {
        $data = $data."</div>";
        $ii = 0;
    }
}
    if ($ii != 10) {
        $data = $data."</div>";
    }

    }else
    echo('No Result');

答案 1 :(得分:0)

if($result)
{
   while()
  {
   -----
   --
   -
   }
}
else
echo "No Result";

答案 2 :(得分:0)

您可以使用以下修改后的代码,但它仍会每十次迭代创建一个新的<div [...] id="gallery">。请注意,HTML ID必须是唯一的。

if ( ( !$result ) || ( 0 == mysql_num_rows( $result ) ) ) {
    echo 'No result';
}
else {
    $data = "";
    $ii = 0;
    $m = 0;
    while ( $myrow = mysql_fetch_array( $result ) ) {
        $ii++;
        $m++;
        if ( $m == 1 ) {
            $data .= '<div class="page current" id="gallery">';
        }
        elseif ( $ii == 1 ) {
            $data .= '<div class="page" id="gallery">';
        }
        $data .= '<a href="#" title="' . $myrow['name'] . '" class="show_fabric" rel="' . $myrow['id'] . '"><img src="' . $image_directory . $myrow['thumbnail'] . '" width="100px" height="100px"><div class="fb_name">' . $myrow['name'] . "</div></a>\n";
        if ( $ii == 10 ) {
            $data .= "</div>";
            $ii = 0;
        }
    }
    if ( $ii != 10 ) {
        $data .= "</div>";
    }
    echo $data;
}