dtjzpg5313 2014-08-20 06:03
浏览 38

将数据库信息提取到表中

I want to make offer for my hosting company. I made a table with the offers:

CREATE TABLE `planes` (
  `id` int(5) unsigned NOT NULL auto_increment,
  `DiskSpace` text NOT NULL,
  `AnnuallyDataTransfer` text NOT NULL,
  `FTPAccounts` text NOT NULL,
  `EmailBoxes` text NOT NULL,
  `BandwidthAllowance` text NOT NULL,
  `FreeDomains` text NOT NULL,
  `MySQLDatabases` text NOT NULL,
  `price` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;


INSERT INTO `planes` VALUES (1, '5GB', 'Unlimited', '25', '1000', 'Unlimited', '1', 'Unlimited', '200 LE');
INSERT INTO `planes` VALUES (2, '10 GB', 'Unlimited', '50', '1000', 'Unlimited', '1', 'Unlimited', '300');

Then I tried to show that offers in php codes. Here is the code:

<?php
    $result = mysql_query("SELECT * FROM planes ORDER BY id DESC LIMIT 0,2") or die(mysql_error());
    $Disc = 1;
    echo '<table class="ranking">';
    echo '<tr><td class="rankhead">#</td><td class="rankhead">Plan1</td><td class="rankhead">Plan2</td><td class="rankhead">plan3</td></tr>';
    while($row = mysql_fetch_array( $result )){
        $name =  $row['AnnuallyDataTransfer'];
        $Disc = $row['FTPAccounts'];
        $class = $row['EmailBoxes'];

        echo '<tr>';
        echo '<td class="rankvalues">'.$Disc.'</td>';
        echo '<td class="rankvalues">'.$name.'</td>';
        echo '<td class="rankvalues">'.$Disc.'</td>';
        echo '<td class="rankvalues">'.$class.'</td>';

        $Disc++;
        echo "</tr>"; 
    }
    echo "</table>";
?>

But I got error design. I want to show all the offers field into the left as a column and offers on row and each offer has has it's value from the field on the left.

  • 写回答

1条回答 默认 最新

  • dongyi0114 2014-08-20 06:08
    关注

    you are using $Disc variable for such increament and database value correct them

    try this

    while($row = mysql_fetch_array( $result )){
          $AnnuallyDataTransfer =  $row['AnnuallyDataTransfer'];
          $FTPAccounts = $row['FTPAccounts'];
          $EmailBoxes = $row['EmailBoxes'];
    
          echo '<tr>';
          echo '<td class="rankvalues">'.$Disc.'</td>';
          echo '<td class="rankvalues">'.$AnnuallyDataTransfer.'</td>';
          echo '<td class="rankvalues">'.$FTPAccounts.'</td>';
          echo '<td class="rankvalues">'.$EmailBoxes.'</td>';
    
          $Disc++;
          echo "</tr>"; 
    }
    

    NOTE : mysql_* is deprecated use mysqli_* or pdo

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测