The following needs to be displayed:
Display all items of a certain fabric
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))开发者_Python百科 echo "No result";
else echo $data;
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)
{
while()
{
-----
--
-
}
}
else
echo "No Result";
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;
}
精彩评论