Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP while循环变量不会递增_Php_Mysql_Html Table - Fatal编程技术网

PHP while循环变量不会递增

PHP while循环变量不会递增,php,mysql,html-table,Php,Mysql,Html Table,我使用一个变量$x来跟踪循环运行了多少次,并使用它来结束表中的行。但是,每次循环通过它时,$x都设置为0 $x=0; function getname($gid) { $query2="SELECT UID FROM gallery WHERE GID = '$gid'"; $result2=mysql_query($query2) or die(mysql_error()); $row2=mysql_fetch_array($result2); global

我使用一个变量$x来跟踪循环运行了多少次,并使用它来结束表中的行。但是,每次循环通过它时,$x都设置为0

$x=0;

function getname($gid)
{
    $query2="SELECT UID FROM gallery WHERE GID = '$gid'";
    $result2=mysql_query($query2) or die(mysql_error());
    $row2=mysql_fetch_array($result2);
    global $uid;
    $uid=$row2['UID'];

    $query3="SELECT user FROM login WHERE id='$uid'";
    $result3=mysql_query($query3) or die(mysql_error());
    $row3=mysql_fetch_array($result3);
    global $creator;
    $creator=$row3['user'];
}

$query="SELECT * FROM photos ORDER BY DATE LIMIT $offset, 20 ";
$result=mysql_query($query) or die(mysql_error());
$row=mysql_fetch_array($result);
while($row=mysql_fetch_array($result))
{
    $gid=$row['gid'];
    $pid=$row['pid'];
    $name=$row['photo'];

    getname($gid);

    $photo="photos/".$row['pid'].".".$row['type'];

    echo "<table border=1>";

    if ($x=0)
    {
        echo "<tr>";
        echo "yes";
    }

    $max_width = 100;
    $max_height = 100;
    list($width, $height) = getimagesize($photo);
    $w=$width;
    $h=$height;
    if($width > 100 or $height > 100)
    {
        $ratioh = $max_height/$height;
        $ratiow = $max_width/$width;
        $ratio = min($ratioh, $ratiow);
        // New dimensions
        $width = intval($ratio*$width);
        $height = intval($ratio*$height);
    }

    echo "<td><a href=view.php?pid=$pid> <img src=$photo width=$width height=$height /><big><font color=beige ><center>$name</center></font></big></a>";
    echo "<a href=user.php?uid=$uid><small><center>$creator</center></small></a></td>";
    echo $x;
    $x++;
    echo $x;
    if ($x=5)
    {
        echo "</tr>";
        $x=0;
    }
}
echo "</table>";

图片确实显示得很好,大小适当,但每张照片都位于不同的行上。我想做的是在每行上放5个缩略图,然后下一行再显示5个。但是,由于变量不断重置,我无法将它们全部放在正确的行中。非常感谢您的帮助。但是,由于变量一直在重置,我无法

您需要使用相等运算符,而不是赋值运算符

if ($x=0) // this sets x to 0, and the expression returns true 
          // if the assignment succeed (it always does)

if ($x==0) // this checks if x is zero. and returns true/false based on that.

您使用了错误的等号进行比较。如果$x=0,则将$x的值设置为零。您需要改用if$x==0。

赋值运算符不返回true或false。它返回指定的值,在本例中为零。唉,我想我们在某些时候都会犯这样的小错误。非常感谢。