简体   繁体   English

在HTML表中显示SQL查询的结果

[英]Displaying the result of an SQL query in an HTML table

I'm stuck for a while, I try to display the result of a variable that executes a sql query in an html table, here is my code; 我被卡住了一段时间,我尝试在html表中显示执行sql查询的变量的结果,这是我的代码;

$REQUT = Doctrine_Query::create()
->select('DISTINCT r.prod , r.di, COUNT(*) as Result')
->from('tabl r')
->groupBy('r.di')
->orderBy('Result ASC') ;

$REQUT->fetchArray();

PS : I work in symfony, I am looking to have a view like mysql PS:我从事symfony工作,我希望拥有像mysql这样的视图

You need to loop through the result set. 您需要遍历结果集。 I don't know this particular API, but assuming it works similarly to others: 我不知道这个特定的API,但假设它的工作原理与其他类似:

$REQUT = // all that query stuff
while($ROW = $REQUT->fetchArray()) {
    // do something
    var_dump($ROW);
}

You can try this to display as a html table... 您可以尝试将其显示为html表...

 $REQUT = Doctrine_Query::create()
->select('DISTINCT r.prod , r.di, COUNT(*) as Result')
->from('tabl r')
->groupBy('r.di')
->orderBy('Result ASC') ;

echo "<table>";
while($ROW = $REQUT->fetchArray()) 
{

echo "<tr><td>".$ROW["prod"]."<td>";
echo "<td>".$ROW["di"]."<td></tr>";
}
echo "</table>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM