PHP迭代订单

时间:2016-03-11 14:40:58

标签: php

您好,

      <html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="Mosaddek">
    <meta name="keyword" content="FlatLab, Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, Retina">
    <link rel="shortcut icon" href="img/favicon.png">

    <title>Cockburn Highschool BTEC Physical Education</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet" />

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media     queries -->
    <!--[if lt IE 9]>
      <script src="js/html5shiv.js"></script>
      <script src="js/respond.min.js"></script>
    <![endif]-->
  </head>
<?php
    # 0 = Preset; 1 = Words
    $servername     = getenv('localhost');
    $username    = 'seclyps';
    $password    = "";
    $database    = "keywords";
    $dbport      = 3306;

    // Create connection
    $db = new mysqli($servername, $username, $password, $database, $dbport);

    // Check connection
    if ($db->connect_error) {
        die("Connection failed: " . $db->connect_error);
    } 
    #echo "Connected successfully (".$db->host_info.")";
    $questionid = "3";

    $sql = "SELECT `question`,`noresponse`,`nopreset`,`response`,`preset`,`order` FROM `questions` WHERE `questionid` = '$questionid'";
    if($result = $db->query($sql))
    {
      while ($row = $result->fetch_assoc())
      {
         $question       = $row["question"];
         $noresponse     = $row['noresponse'];
         $nopreset       = $row['nopreset'];
         $response       = $row['response'];
         $preset         = $row['preset'];
         $order          = $row['order'];
        // echo "Question:";
        // echo $row["question"]."<br>";
        // echo " Number of Response Boxes:";
        // echo $row['noresponse']."<br>";
        // echo " Number of Preset Words:";
        // echo $row['nopreset']."<br>";
        // echo "Response words seperated by a space:";
        // echo $row['response']."<br>";
        // echo "Preset words seperated by a space:";
        // echo $row['preset']."<br>";
        // echo $order;
        #TODO: Array and Splitter for the Response and Preset Words
        $arrayrw = array();
        $responsewords = explode(" ",$response);
        $presetwords = explode(" ", $preset);
        $orderexplode = str_split($order, 1);
        $pos = strpos($order, $findme); 


        print_r($orderexplode);
        print_r($responsewords);
        #++ For [$++] preset word preset word
        #if order is not resetting whenwe change
        for ($os = 0; $os <= strlen($order) ; $os++)
        {
         #echo $order[$os];  
         if($order[$os] === "0")
         {
                echo strpos($order[$os], "0");
                echo "<br>"."<label>".$presetwords[$os]."</label>"." ";
         }
         if($order[$os] === "1")
         {
                echo "<input type='text' class='form-control' placeholder=''>";
         }
        }


        // for ($rsw = 0; $rsw <= $noresponse; $rsw++ )
        // {
        //     $arrayrw = array();
        //     array_push($arrayrw, $response);
        //     echo $arrayrw[$rsw];
        // }
        // for ($nrb = 1; $nrb <= $noresponse; $nrb++ )
        // {
        //     echo "<input type='text' class='form-control' placeholder=''>";
        //     array_push($responsewords, $response);
        //     echo $response;
        // }
        // echo "<br>";
        // for ($npb = 1; $npb <= $nopreset; $npb++ )
        // {
        //     echo "<input type='text' class='form-control' placeholder=''>";
        // }
      }
    }
    // fetch the result row.
    ?>

我正在使用此代码获取字符串$order,然后根据它是1还是0放置一个html对象,但在它找到1之后在2 0's之后,$os比要打印的字符串中的正确值所需的1$.ajax({ method: "POST", url: "test.php", data: data }).done(function(resp){ res = resp; }); return res; 。无论如何要解决这个问题。

0 个答案:

没有答案