Javascript 需要循环查看一系列mysql查询结果

Javascript 需要循环查看一系列mysql查询结果,javascript,php,mysql,Javascript,Php,Mysql,我需要连续地从一个MySQL表中为一个Kiosk循环14个查询结果 显示每个结果10秒钟 任何例子都可以用PHP或JS编写 现在我有14个php文件,我循环使用这个元http equiv=\refresh\content=\10;url=ccml2.php\每个页面上的页面都会更改以转到下一个页面,最后一个页面指向第一个页面。 但我认为必须有一种方法可以通过一个php文件来实现这一点。 每个查询都会更改“选择位置”以获取需要显示的值。 e、 g.从表中选择字段1、字段2,其中字段3=值。 执行查

我需要连续地从一个MySQL表中为一个Kiosk循环14个查询结果

显示每个结果10秒钟

任何例子都可以用PHP或JS编写


现在我有14个php文件,我循环使用这个元http equiv=\refresh\content=\10;url=ccml2.php\每个页面上的页面都会更改以转到下一个页面,最后一个页面指向第一个页面。 但我认为必须有一种方法可以通过一个php文件来实现这一点。 每个查询都会更改“选择位置”以获取需要显示的值。 e、 g.从表中选择字段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\">&nbsp;%d</td>",$row[2]);                //Match ID
  printf("<td class=\"t3\">&nbsp;%s</td>",$row[3]);                // Name
  printf("<td class=\"t2\"> %6.2f &nbsp;</td>",$row[4]);           //Stage 1 Time
  printf("<td class=\"t2\"> %6.2f &nbsp;</td>",$row[5]);           //Stage 2 Time
  printf("<td class=\"t2\"> %6.2f &nbsp;</td>",$row[6]);           //Stage 3 Time
  printf("<td class=\"t2\"> %6.2f &nbsp;</td>",$row[7]);           //Stage 4 Time
  printf("<td class=\"t2\"> %6.2f &nbsp;</td>",$row[8]);           //Stage 5 Time
  printf("<td class=\"t4\"> %6.2f &nbsp;</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);
?>

请给我们更多的细节。分享你现有的代码会很有帮助。我如何回答这两个回应者?现在我有14个php文件,我循环使用这些文件。每个页面上的页面更改转到下一个页面,最后一个指向第一个页面。但我认为必须有一种方法可以通过一个php文件来实现这一点。每个查询都会更改“选择位置”以获取需要显示的值。e、 g.从表中选择字段1、字段2,其中字段3=值。执行查询,显示结果10秒,更改为下一个值,重复。值可以是1到14。希望这有助于取消暂停