需要循环遍历一系列mysql查询结果
Need to cycle through a sequence of mysql query results
对于Kiosk ,我需要连续循环使用MySQL表中的14个查询结果
显示每个结果10秒
PHP或JS 中的任何示例都将受到赞赏
现在我有14个php文件,我用这个meta http equiv=''"refresh''"content=''"10;url=ccml2.php"循环浏览这些文件,每个文件上的页面都会更改为转到下一页,最后一页指向第一页。但我认为,必须有一种方法可以通过一个php文件来实现这一点。每个查询都会更改选择时的位置,以获取显示所需的值。例如从表中选择字段1、字段2,其中字段3=值。进行查询,显示结果10秒,更改为下一个值,重复。值可以是1到14
这是第一次尝试,但没有达到我认为应该达到的效果
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
if (mysqli_connect_errno()) {
printf("Connect failed: %s'n", mysqli_connect_error());
exit();
}
$query = sprintf("SELECT ClassName, ClassId FROM class");
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
while($row = $result->fetch_assoc())
{
$ICName[]=$row['ClassName']; //gets 14 Class Names
$IC_Id[] = $row['ClassId']; // gets matching ID 1 to 14
}
for($x=0;$x<$result->num_rows;$x++)
{
echo "<html>";
echo "<body>";
echo "<head>";
echo "<Title>Cactus Combat Match League</Title>";
echo "<link type='"text/css'" rel='"stylesheet'" href='"ccml.css'" media='"all'" />";
echo "</head>";
echo "<img width='"1280'" height='"190'" src='"images/Banner.png'"></img>";
echo "<p></p>";
echo "<p></p>";
echo "<h2>Thursday Night Match Scores 11/14/2013</h2>";
echo "<table border='"1'" width='"1200'" align='"center'">";
echo "<tr>";
echo "<th class='"th1'" colspan = '"8'">".$ICName[$x]."</th>"; // Display Class Name
echo "</tr>";
echo "<tr>";
echo "<th class='"th2'">#</th>";
echo "<th class='"th2'">Name</th>";
echo "<th class='"th2'">Stage 1</th>";
echo "<th class='"th2'">Stage 2</th>";
echo "<th class='"th2'">Stage 3</th>";
echo "<th class='"th2'">Stage 4</th>";
echo "<th class='"th2'">Stage 5</th>";
echo "<th class='"th2'">TOTAL</th>";
echo "</tr>"; // following gets results for this Class
$query1 = sprintf("SELECT mid, SName, Stage1, Stage2, Stage3, Stage4, Stage5, Total FROM shooter WHERE cid=".$IC_Id[$x]." AND mdate='2013-11-14' ORDER BY Total");
$result1 = $mysqli->query($query1) or die($mysqli->error.__LINE__);
while ($row1 = $result1->fetch_assoc()) // Display Results
{
echo "<tr>";
echo "<td class='"t1'">".$row1['mid']."</td>";
echo "<td class='"t3'">".$row1['SName']."</td>";
echo "<td class='"t2'">".number_format((float)$row1['Stage1'], 2, '.', '')."</td>";
echo "<td class='"t2'">".number_format((float)$row1['Stage2'], 2, '.', '')."</td>";
echo "<td class='"t2'">".number_format((float)$row1['Stage3'], 2, '.', '')."</td>";
echo "<td class='"t2'">".number_format((float)$row1['Stage4'], 2, '.', '')."</td>";
echo "<td class='"t2'">".number_format((float)$row1['Stage5'], 2, '.', '')."</td>";
echo "<td class='"t4'">".number_format((float)$row1['Total'], 2, '.', '')."</td>";
echo "</tr>";
}
echo "</table>";
echo "</body>";
echo"</html>";
sleep(1);
}
mysqli_close($mysqli);
?>
我想我找到了一个稍微更优雅的解决方案。
问题:射击比赛的顺序显示结果(由25个等级的结果组成),然后是按比赛时间顺序显示的射击运动员数量,然后是比赛中每个阶段的前三名射击运动员。存储在MySQL数据库中的结果)。
每个结果都会根据匹配日期进行筛选。
初始化一张表格,其中包括每节课的开始、站立、站立的部分、阶段和比赛日期
如果每个职业中有射手,则首先显示该职业5秒,如果没有,则显示1秒。然后一次显示射手12的排名,直到完成。然后显示每个阶段的前三名射手。
我只显示第一个的代码(显示每个射击类的结果)
也许有一种更优雅的方法可以做到这一点,但这很有效。其他两个基本相同,只是数据和表格不同。代码的开头
// What Class to Deal with and What Match Date to Display
$query = sprintf("SELECT class_cnt, thur FROM CCnt");
$result = mysqli_query($link, $query);
while ($row = mysqli_fetch_row($result))
{
$Class_Id = $row[0]; // Set the Class ID from the database
$rdate=row[1]; // Set the Date of the Match to Display
}
mysqli_free_result($result);
// Format Display Date in M-D-Y format
$pieces = explode("-", $rdate);
$ddate = $pieces[1]."/".$pieces[2]."/".$pieces[0];
// Get the Name of the Class
$query = sprintf("SELECT ClassName FROM class WHERE ClassId=%d", $Class_Id);
$result = mysqli_query($link, $query);
while ($row = mysqli_fetch_row($result))
{
$ICName = $row[0];
}
mysqli_free_result($result);
// Select Data to Display
$query = sprintf("SELECT mdate, cid, mid, SName, Stage1, Stage2, Stage3, Stage4, Stage5, Total FROM shooter WHERE cid=%d AND mdate='%s' ORDER BY Total", $Class_Id, $rdate);
$result = mysqli_query($link, $query);
// Adjust refresh time based on if there are Results
$row_cnt = mysqli_num_rows($result);
if ($row_cnt > 0)
$dtime = 5; // 5 deconds if results
else
$dtime = 1; // 1 second if none
// Start of HTML Output
echo "<?xml version='"1.0'" encoding='"iso-8859-1'"?>";
echo "<!DOCTYPE html PUBLIC '"-//W3C//DTD XHTML 1.1//EN'" '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'">";
echo "<html xmlns='"http://www.w3.org/1999/xhtml'">";
echo "<head>";
printf("<Title>Cactus Combat %s Results</Title>", $ICName ); // Title the page
echo "<link type='"text/css'" rel='"stylesheet'" href='"ccml.css'" media='"all'" />"; // Get Style file
// Check to see what Class to display
switch ($Class_Id)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
printf("<meta http-equiv='"refresh'" content='"%d; url=ccml1.php'">", $dtime); // Class ID = 1 - 24 Refresh to same page
break;
case 25:
printf("<meta http-equiv='"refresh'" content='"%d; url=ccml2.php'">", $dtime); // Class ID = 25 Set to Next Page
break;
}
$Class_Id++; // Increment the Class ID
echo "</head>";
echo "<body>";
echo "<img width='"1280'" height='"190'" src='"images/Banner.png'"></img>"; // Display the Banner
echo "<p></p>";
echo "<p></p>";
echo "<h2>Thursday Night Match Scores ".$ddate."</h2>";// Display the Date of the Match
echo "<table>";
echo "<tr>";
echo "<th class='"th1'" colspan = '"8'">".$ICName."</th>"; // Display Which Class these Results are
echo "</tr>";
echo "<tr>"; // Output Table Headers
echo "<th class='"th2'">#</th>";
echo "<th class='"th3'">Name</th>";
echo "<th class='"th4'">Stage 1</th>";
echo "<th class='"th4'">Stage 2</th>";
echo "<th class='"th4'">Stage 3</th>";
echo "<th class='"th4'">Stage 4</th>";
echo "<th class='"th4'">Stage 5</th>";
echo "<th class='"th4'">TOTAL</th>";
echo "</tr>";
// Put Data into HTML Table Rows
while ($row = mysqli_fetch_row($result))
{
echo "<tr>"; // Output Data Row
printf("<td class='"t1'"> %d</td>",$row[2]); //Match ID
printf("<td class='"t3'"> %s</td>",$row[3]); // Name
printf("<td class='"t2'"> %6.2f </td>",$row[4]); //Stage 1 Time
printf("<td class='"t2'"> %6.2f </td>",$row[5]); //Stage 2 Time
printf("<td class='"t2'"> %6.2f </td>",$row[6]); //Stage 3 Time
printf("<td class='"t2'"> %6.2f </td>",$row[7]); //Stage 4 Time
printf("<td class='"t2'"> %6.2f </td>",$row[8]); //Stage 5 Time
printf("<td class='"t4'"> %6.2f </td>",$row[9]); //Stage Total Time
echo "</tr>";
}
echo "</table>";
echo "</body>";
echo"</html>";
mysqli_free_result($result);
// Update Class to Display in database
if ($Class_Id > 25) // Check to see if we are done IF Yes reset the Class ID
$Class_Id = 1;
$UpdQuery = sprintf("UPDATE CCnt SET class_cnt = %d", $Class_Id);// Update Class ID
mysqli_query($link, $UpdQuery);
mysqli_close($link);
?>
相关文章:
- 更新从Mysql查询检索到的数据?Node.js节点mysql
- 浓缩一系列mySQL查询
- 如何翻译MySQL查询's ResultSet转换为整数
- 如何在mysql查询(NODE.js)中重复使用一个参数
- onclick->mysql查询->javascript;同一页
- 向更新mysql查询传递一个id
- 如何在下拉列表更改时自动填充mysql查询结果中的文本框值
- mysql查询一次在单个查询中的多个表中插入记录
- 添加行并运行多个mySQL查询
- 如何将mysql查询的结果获取到html文本框中
- 数组数据排序类似mysql查询
- 使用jquery显示mysql查询结果
- 通过 AJAX 调用 PHP 文件,将 $_GET 变量传递到 MySQL 查询中,然后回显到响应中
- 使用 mysql 查询从单列返回值
- 如何使用表值来使用PHP驱动mySQL查询
- php中的mysql查询不起作用,但它在另一个php文件中起作用
- 使用MySQL查询或javascript进行数据优化
- 如何在nodejs中的MySQL查询中使用多个变量
- 如何在不输出结束PHP标签“?>”的情况下将PHP MySQL查询回显到Javascript变量中
- 模型对象构造函数中的节点mysql查询