我需要不断循环查询来自MySQL表的14个查询结果以获取Kiosk
显示每个结果10秒
任何示例都可以在PHP或JS
中受到赞赏现在我有14个php文件,我循环使用这个元http-equiv = \“refresh \”content = \“10; url = ccml2.php \”每个页面都会改变以转到下一页,最后一点指向第一个。 但我认为必须有一种方法可以用一个php文件来做到这一点。 每个查询都会更改select的位置以获取显示所需的值。 例如从表中选择field1,field2,其中field3 = value。 查询,显示结果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);
?>
答案 0 :(得分:0)
我想我找到了一个更优雅的解决方案。
问题:序列显示来自射击比赛(包括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);
?>