HTML表格列由php控制

时间:2016-07-26 21:21:01

标签: php html mysql pagination html-table

我只是制作一个HTML表格,它可以通过php代码控制,但我发现问题在这里,我无法理解为什么会发生这种情况,首先有一个差距,然后它从数据库ID号开始,这是我的PHP码,

    <?php
error_reporting(E_ERROR | E_PARSE);
include('connect.php');  



    // Get page data
    $query = "SELECT * FROM profile ORDER BY `id` ASC";
    $rs1 = mysql_query($query);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Barat Store Product Profile</title>
<style type="text/css">
<!--
#apDiv1 {
    position:absolute;
    left:0px;
    top:0px;
    width:1294px;
    height:171px;
    z-index:1;
}
#apDiv2 {
    position:absolute;
    left:0px;
    top:174px;
    width:100%;
    height:100%;
    z-index:2;
}
#apDiv3 {
    position:absolute;
    left:621px;
    top:107px;
    width:186px;
    height:57px;
    z-index:3;
    font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
    font-size: 32px;
    font-weight: bolder;
    color: #F00;
}
#apDiv3 a {
    color: #F00;
    text-decoration: none;
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
-->
</style>
</head>

<body>
<div id="apDiv1">IMAGE</div>
<div id="apDiv2">
<table width="100%" border="0">
    <tr>
    <?php
$rs1_endRow = 0;
$rs1_columns = 3; // number of columns
$rs1_hloopRow1 = 1; // first row flag
do {
    if($rs1_endRow == 0  && $rs1_hloopRow1++ != 0) echo "<tr>";
   ?>
<td height="100%"><?php echo $row_rs1['id']; ?><br />
<a href="ASASAS#.php?id=<?php echo $row_rs1['id']; ?>" target="_blank"><?php echo $row_rs1['name']; ?><br />
      <img src="#<?php echo $row_rs1['id']; ?>.jpg.jpg" width="400" height="280" />      <br />
    </a></td>
    <?php $rs1_endRow++;
if($rs1_endRow >= $rs1_columns) {
  ?>
  </tr>
  <?php
$rs1_endRow = 0;
  }
} while ($row_rs1 = mysql_fetch_array($rs1));
if($rs1_endRow != 0) {
while ($rs1_endRow < $rs1_columns) {
    echo("<td>&nbsp;</td>");
    $rs1_endRow++;
}
echo("</tr>");
}?>
  </table>
</div>
<div id="apDiv3"><a href="page2.php">2nd Page</a></div>
</body>
</html>

这是我的sql代码:

    -- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jul 26, 2016 at 11:11 PM
-- Server version: 10.1.13-MariaDB
-- PHP Version: 5.5.35

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `probarat`
--

-- --------------------------------------------------------

--
-- Table structure for table `profile`
--

CREATE TABLE `profile` (
  `id` int(11) NOT NULL,
  `name` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `profile`
--

INSERT INTO `profile` (`id`, `name`) VALUES
(1, 'AMLOKI (INDIAN)'),
(2, 'ANAR DODHI'),
(3, 'AL-VALUKA'),
(4, 'AKARKORA (NUM.1)'),
(5, 'AKARKORA (NUM.2)'),
(6, 'ATMORA'),
(7, 'ANAR DANA'),
(8, 'ADA SOOT (NUM.1)'),
(9, 'AKRABIJ (DORENJO)'),
(10, 'AFTIMUN'),
(11, 'ANJIBAR'),
(12, 'ASHOGONDHA (DESHI)'),
(13, 'ASHOGONDHA (NUM.2)'),
(14, 'ALOYA (MOSABBAR)'),
(15, 'ATUS'),
(16, 'AMLOKI (DESHI)'),
(17, 'AORJUN CHAL'),
(18, 'AL VALU'),
(19, 'ANANTOMUL'),
(20, 'ARBI GUM'),
(21, 'ANARFUL'),
(22, 'BELA GOTA'),
(23, 'BOOJ PATA'),
(24, 'BHAMAN LAL'),
(25, 'BONGSHOLOCHON'),
(26, 'BUCHKI DANA'),
(27, 'B.K KASNI'),
(28, 'BIS FAIJ'),
(29, 'BOHERA'),
(30, 'BIJ LONG'),
(31, 'BADIYAN'),
(32, 'BARENGO SEP'),
(33, 'BUJI DANA'),
(34, 'BABUNA'),
(35, 'BIRONGO DANA'),
(36, 'CHIROTA'),
(37, 'DAIFUL'),
(38, 'DALIM CHALA'),
(39, 'DARHORIDRA'),
(40, 'DARHORIDRA CHAL'),
(41, 'CHAL - MUGORA'),
(42, 'CUNIYA GUM'),
(43, 'FUNDUK'),
(44, 'ISPAGUL HUSK (VUSHI)'),
(45, 'JOIN (ORGINAL)'),
(46, 'GOLAP FUL (NUM.1)'),
(47, 'GOLAP FUL (NUM.2)'),
(48, 'GOR BOCH'),
(49, 'JOISTI MODHU (CUTTING) (NUM.1)'),
(50, 'JOISTI MODHU (REKCIN) (NUM.2)'),
(51, 'JOISTI MODHU (REKCIN) (NUM.3)'),
(52, 'HORTOKI JUNGLI'),
(53, 'HENA JAL (30KG)/ (50KG)'),
(54, 'GOKUR KATA'),
(55, 'HING'),
(56, 'GUGUL (INDIA)'),
(57, 'GUGUL (PAKISTANI)'),
(58, 'GAOJABON'),
(59, 'HORTUKI'),
(60, 'GORMAR BOTI/PATA'),
(61, 'JOHORMOHRA'),
(62, 'JAMAL GOTA'),
(63, 'JOTAMANSHI (NUM.1)'),
(64, 'GULE JUFA'),
(65, 'INDROJOB RED'),
(66, 'KUTKI'),
(67, 'KAKRASHING'),
(68, 'LOCHCHAL'),
(69, 'KUCHILA'),
(70, 'KHOSH'),
(71, 'KHORASANI JOIN'),
(72, 'LAL CHONDON'),
(73, 'KATILA (NUM.1)'),
(74, 'KATILA (NUM.2)'),
(75, 'KATILA (NUM.3)'),
(76, 'KUNDOR'),
(77, 'KALO MEGH'),
(78, 'KALO DANA'),
(79, 'LAL DANA'),
(80, 'KUMKUM'),
(81, 'KATILA CUTTING'),
(82, 'METHI (INDIA)'),
(83, 'METHI (DESHI)'),
(84, 'MAJUFOL (GREEN)'),
(85, 'MAJUFOL (WHITE)'),
(86, 'MARJAN'),
(87, 'MONJESTA'),
(88, 'MOHURI'),
(89, 'MAKU DANA'),
(90, 'MOTA BOCH'),
(91, 'MEHEDI PATA'),
(92, 'NEPALI KHOR (RAKCIN)'),
(93, 'NAGOR MOTHA'),
(94, 'PARSUSA'),
(95, 'PIPUL (CHOTO DANA)'),
(96, 'PIPUL (GOL DANA)'),
(97, 'PIPUL (S.P INDIAN)'),
(98, 'RITHA (NUM.1)'),
(99, 'REWCHINI'),
(100, 'ROTON JUT'),
(101, 'TOKME ISPAST'),
(102, 'SONAPATA'),
(103, 'SAHI JIRA'),
(104, 'SOYLOJ'),
(105, 'SADA KORI'),
(106, 'TOKME KHATMI'),
(107, 'TOKME KHOBBAJI'),
(108, 'TOKME KASHNI'),
(109, 'SUNRISE KHOR'),
(110, 'SADA CHONDON'),
(111, 'TOKME KARAF'),
(112, 'TOKME HAMMAJ'),
(113, 'SAPISTAN'),
(114, 'SILAJEET'),
(115, 'SALEM GOTA'),
(116, 'SAKAKUL MISRI'),
(117, 'TOP CHINI'),
(118, 'TOJ (LALUKA)'),
(119, 'SURONJON'),
(120, 'TAL MAKHNA (INDIAN)'),
(121, 'TAL MAKHNA (DESHI)'),
(122, 'TOKMA (KALA TULSI)'),
(123, 'THANKUNI PATA'),
(124, 'SURMA KALO'),
(125, 'SURMA SADA'),
(126, 'TOKME KASUS'),
(127, 'S.K.F KHOR'),
(128, 'SORNOLOTA'),
(129, 'SIMUL MUL'),
(130, 'UDE KUDDUS'),
(131, 'UDE SALIB'),
(132, 'UNNAB'),
(133, 'ISABGUL DANA'),
(134, 'KAKULI'),
(135, 'TOKME KHAKSI'),
(136, 'TOKME ISPAK');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `profile`
--
ALTER TABLE `profile`
  ADD PRIMARY KEY (`id`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

这是我的结果照片:

enter image description here

请尽快帮助我。

2 个答案:

答案 0 :(得分:1)

你得到它是因为你告诉它输出:

do {
    if($rs1_endRow == 0  && $rs1_hloopRow1++ != 0) echo "<tr>";
   ?>
<td height="100%"><?php echo $row_rs1['id']; ?><br />
                                 ^^^^---undefined
    [..snip...]
} while ($row_rs1 = mysql_fetch_array($rs1));
           ^---until this executes

由于$row_rs1在do / while循环的第一次迭代之后才设置,因此输出一堆未定义的变量。

答案 1 :(得分:-1)

请看这一行:<img src="#<?php echo $row_rs1['id']; ?>.jpg.jpg" width="400" height="280" />

确保图片路径正确无误,我怀疑你有&#34; .jpg.jpg&#34;

使用&#34; Inspector&#34;从您的浏览器确保图像链接正确。