echo sql 或显示“无项目”

发布于 2024-11-08 03:07:09 字数 935 浏览 0 评论 0原文

需要显示以下内容:

  1. 显示某个fabric的所有项目

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

该代码对于第一点来说功能齐全,但不支持第二点功能。 非常感谢您的帮助。

//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;

The following needs to be displayed:

  1. Display all items of a certain fabric

  2. If no fabrics are available in the sql display "no result"

The code is fully functional for the first point but does not support the second feature.
Many thanks for helping out.

//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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黑色毁心梦 2024-11-15 03:07:09
    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');
    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');
谈下烟灰 2024-11-15 03:07:09
if($result)
{
   while()
  {
   -----
   --
   -
   }
}
else
echo "No Result";
if($result)
{
   while()
  {
   -----
   --
   -
   }
}
else
echo "No Result";
和我恋爱吧 2024-11-15 03:07:09

您可以使用以下修改后的代码,但它仍然每十次迭代创建一个新的

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;
}

You could use the following modified code, but it still creates a new <div [...] id="gallery"> every ten iterations. Note that HTML IDs must be unique.

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文