如何设置和破坏PHP查询的结果

时间:2018-04-23 09:55:00

标签: php css database sql-server-2012

请帮帮我。

我有一个PHP代码,它从数据库中获取结果并以滚动形式显示在网站中。现在我想设置这个选框

以下是我的PHP代码

<?php
$data_source='ss';
$user='su';
$password='pass';

// Connect to the data source and get a handle for that connection.
$conn=odbc_connect($data_source,$user,$password);
if (!$conn){
    if (phpversion() < '4.0'){
      exit("Connection Failed: . $php_errormsg" );
    }
    else{
      exit("Connection Failed:" . odbc_errormsg() );
    }
}
$sql="SELECT MARKETNAME, COMMODITY, MAXPRICE
FROM(
  SELECT *, ROW_NUMBER()OVER(PARTITION BY commodity ORDER BY Date desc ,maxprice Desc) rn
    FROM markets where NOT date=DATEADD(day, DATEDIFF(day,0, GETDATE()), 0) and commodity IN('Bengal gram','Bajra','Black gram','Green gram','Copra','Horse    gram','Tur','Jowar','Ragi','Maize','Paddy','Groundnut','Safflower','Sesamum','Sunflower','Dry Chilli','Tamarind','Turmeric','Arecanut','Coconut','Red gram','Cotton','Jaggery'))X
WHERE rn=1";

# Execute the statement.
$rs=odbc_exec($conn,$sql);

// Fetch and display the result set value.
if (!$rs){
    exit("Error in SQL");
}
echo '<marquee onmouseover="this.stop()" onmouseout="this.start()">';
echo '<a href="http://localhost:/show2.php">';
while( $row = odbc_fetch_array($rs) ) {
$res=implode("->",$row);
echo '|';
print_r($res);
echo "|";
echo '&nbsp;&nbsp;&nbsp;&nbsp;';
//echo '&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
}
echo '</a>';
echo '</marquee>';
// Disconnect the database from the database handle.
odbc_close($conn);
?>

上述程序的输出如下所示

 |marketname->commodity->maxprice|  ......

我想要这样

commodity(marketname)   |   commodity(marketname)   |  ........
      maxprice          |          maxprice         |

此处商品(市场名称)应采用粗体和不同颜色。 maxprice 常规尺寸和不同颜色。

我怎么能实现这个目标?

1 个答案:

答案 0 :(得分:0)

在marquee标签中尝试这个,

while( $row = odbc_fetch_array($rs) ) {

$commodity=$res['COMMODITY'];
$market_name=$res['MARKETNAME'];
$max_price=$res['MAXPRICE'];

echo '|';
echo  $commodity."(".$market_name.")";    
echo '|';
echo $max_price;    
//echo '&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
}