我怎么打印到桌子?

时间:2011-01-21 19:12:13

标签: php printing echo

如果有人愿意告诉如何回应/打印,我将不胜感激。

下面是在插入数据之前将数据输入数据库的过程,如何将其回显到表中?

<?php
session_start();
if(isset($_POST['submit']))
{
 include('class/stock_class.php');
 $st = new st_exchange_conv(DEFAULT_SOURCE);
 $from = mysql_real_escape_string(stripslashes($_POST['from']));
 $value = floatval($_POST['amount']);
 $date = date('Y-m-d H:i:s');
 $_SESSION['selected'] = $from;
 $stocks = $st->stocks();
 asort($stocks);
 foreach($stocks as $key=>$stock)
 {
  $st->convert($from,$key,$date);
  $stc_price = $st->price($value);
  $stock = mysql_real_escape_string(stripslashes($stock));
  $count = "SELECT * FROM oc_stock WHERE stock = '$key'";
  $result = mysql_query($count) or die(mysql_error());
  $sql = '';
  if(mysql_num_rows($result) == 1)
  {
   $sql = "UPDATE oc_stock SET stock_title = '$stock', stc_val = '$stc_price', date_updated = '$date' WHERE stock = '$key'";
  }
  else
  {  
  $sql = "INSERT INTO oc_stock(stock_id,stock_title,stock,decimal_place,stc_val,date_updated) VALUES ('','$stock','$key','2',$stc_price,'$date')";
  } 
  $result = mysql_query($sql) or die(mysql_error().'<br />'.$sql);
 }
 header("Location: index.php");
 exit();
}
?>

1 个答案:

答案 0 :(得分:2)

插入此内容:

echo "<table><tr><th>".implode(array_keys($stocks), '</th><th>')."</th></tr>";
foreach($stocks as $row) echo "<tr><td>".implode('</td><td>', $row)."</tr>";
echo "</table>";

编辑:如果打印数据是目标而且表格视图并不重要,我建议使用print_r($ stocks)。