Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.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_Image_While Loop_Html Table - Fatal编程技术网

PHP while循环生成一个图像表

PHP while循环生成一个图像表,php,mysql,image,while-loop,html-table,Php,Mysql,Image,While Loop,Html Table,我正在尝试创建一个PHP脚本,它将从数据库中构建一个图像表。我很难弄清楚如何正确地嵌套while循环以生成一个6x(db中有多少个)表。我理解这个概念,但我对PHP还不熟悉,只是不能在这里做 <?php mysql_connect("localhost","root",""); mysql_select_db("images"); $res=mysql_query("SELECT * FROM table1"); echo "<table>"; while($row=my

我正在尝试创建一个PHP脚本,它将从数据库中构建一个图像表。我很难弄清楚如何正确地嵌套while循环以生成一个6x(db中有多少个)表。我理解这个概念,但我对PHP还不熟悉,只是不能在这里做

<?php 

mysql_connect("localhost","root","");
mysql_select_db("images");

$res=mysql_query("SELECT * FROM table1");
echo "<table>";
while($row=mysql_fetch_array($res)){

echo "<tr>";
echo "<td>";?>

<img src="<?php echo $row["images1"]; ?>" height="150" width="150">

<?php echo "</td>";
echo "</tr>";}
echo "</table>";
?>

“height=“150”width=“150”>

如果对已处理的图像数量进行计数,则可以使用
if($count%6==0)
来测试您是否位于列表中的第6项。因此,您的循环如下所示:

$c = 0; //our count
while($row = mysql_fetch_array($res)){
  if(($count % 6) == 0){  // will return true when count is divisible by 6
    echo "<tr>";
  }
  echo "<td>";
  ?>
  <img src="<?php echo $row["images1"]; ?>" height="150" width="150">
  <?php
  echo "</td>";
  $c++;   // Note we are incrementing the count before the check to close the row
  if(($count % 6) == 0){
    echo "</tr>";
  }
}
$c=0;//我们的计数
while($row=mysql\u fetch\u数组($res)){
if(($count%6)==0){//当count可被6整除时,将返回true
回声“;
}
回声“;
?>
“height=“150”width=“150”>

如果您对已处理的图像数量进行计数,则可以使用
if($count%6==0)
测试您是否位于列表中的第6项。因此,您的循环如下所示:

$c = 0; //our count
while($row = mysql_fetch_array($res)){
  if(($count % 6) == 0){  // will return true when count is divisible by 6
    echo "<tr>";
  }
  echo "<td>";
  ?>
  <img src="<?php echo $row["images1"]; ?>" height="150" width="150">
  <?php
  echo "</td>";
  $c++;   // Note we are incrementing the count before the check to close the row
  if(($count % 6) == 0){
    echo "</tr>";
  }
}
$c=0;//我们的计数
while($row=mysql\u fetch\u数组($res)){
if(($count%6)==0){//当count可被6整除时,将返回true
回声“;
}
回声“;
?>
“height=“150”width=“150”>

请注意,
mysql\u*
函数已弃用(请参阅);不要在新代码中使用它们。请注意,
mysql\u*
函数已弃用(请参阅);不要在新代码中使用它们。