0

我正在尝试创建 PHP 分页表.. 但格式如下..

ID:数据
评论:数据
日期:数据

但现在我的桌子是这样的:

ID 注释 日期
数据 数据 数据

任何人都可以让我知道如何改变它?.......我的代码现在是这样的:

<?
    $connection=Mysql_connect('XX','XX','XX');
            if(!$connection)
            {
                echo 'connection is invalid';
            }
            else
            {
                Mysql_select_db('XX',$connection);

            }
    //check if the starting row variable was passed in the URL or not
    if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) {
      //we give the value of the starting row to 0 because nothing was found in URL
      $startrow = 0;
    //otherwise we take the value from the URL
    } else {
      $startrow = (int)$_GET['startrow'];
    }
    //this part goes after the checking of the $_GET var
    $fetch = mysql_query("SELECT * FROM products LIMIT $startrow, 10")or
    die(mysql_error());
       $num=Mysql_num_rows($fetch);
            if($num>0)
            {
            echo "<table border=0  >";
            echo "<tr><td>ID</td><td>Drug</td><td>quantity</td></tr>";
            for($i=0;$i<$num;$i++)
            {
            $row=mysql_fetch_row($fetch);


            echo "<tr>";
              echo"<td>$row[1]</td>";

              echo"<td>$row[2]</td>";
             echo"<td>$row[3]</td>";
            echo"<td >$row[5]</td>";
            echo"</tr>";
            }//for
            echo"</table>";
            }
    //now this is the link..
    echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>';

    $prev = $startrow - 10;

    //only print a "Previous" link if a "Next" was clicked
    if ($prev >= 0)
        echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.$prev.'">Previous</a>';
    ?></td>
                   <td width="331">&nbsp;</td>
                 </tr>
               </table></td>
             </tr>
           </table>
           </td>
      </tr>
    <?php
        include("footer.php");
    ?>

对不起,现在才弄清楚..

$row=mysql_fetch_row($fetch);
        echo "<tr>";
          echo"<td>ID:$row[1]</td>";
           echo "</tr>";
            echo "<tr>";
          echo"<td>Drug:$row[2]</td>";   echo "</tr>";  echo "<tr>";
         echo"<td>QTY:$row[3]</td>";   echo "</tr>";  echo "<tr>";
        echo"<td >Date:$row[5]</td>"
        ;echo "</tr>";  
        echo"</tr>"; echo"<tr height ='20'>";echo"</tr>";
        echo"<tr >";echo"</tr>";echo"<tr >";echo"</tr>";
        }//for
        echo"</table>";
        }
4

1 回答 1

0

哦,我现在明白了!

您可以通过以下方式实现:

<table cellpadding="0" cellspacing="0">
 <tr>
  <th>ID</th>
  <th>Comments</th>
  <th>Date</th>
 </tr>
 <?php 
  if(mysql_num_rows($recordsets) > 0){
   foreach ($recordsets as $recordset): 
 ?>
  <tr>
    <td><?php echo $recordset['id']); ?></td>
    <td><?php echo $recordset['comments']); ?></td>
    <td><?php echo $recordset['date']); ?></td>
   </tr>
  <?php 
      endforeach; 
    } else {
  ?>
  <tr>
   <td colspan="3">No records found !</td>
  </tr>
  <?php 
    }
  ?>
</table>

在这里,第一行将是您的表记录标题信息,然后遍历您的记录结果集。

希望对你有帮助!

于 2013-08-12T14:33:36.517 回答