Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $sql=“插入场馆(VenuName)” . “价值(“$VICENT。”)”; runQuery($sql,“新记录插入$VICENUE[0]”,true); } $sql=“从与会者中选择*”; $result=$conn->query($sql); displayResult($result$sql); $conn->close(); 函数runQuery($sql、$msg、$echoSuccess){ 全球$conn; //运行查询 if($conn->query($sql)==TRUE){ 如果($echoSuccess){ echo$msg.“成功。”; } }否则{ 使用SQL时回显“错误:“.msg.”使用SQL:“.SQL.”“$conn->错误; } }//runQuery()的结尾 函数displayResult($result$sql){ 如果($result->num_rows>0){ 回音“\n”; //打印标题(字段名称) $heading=$result->fetch_assoc(); 回音“\n”; //将字段名称打印为表标题 foreach($key=>$value的标题){ 回显“$key”。\n”; } 回声“; //打印第一行的值 回声“; foreach($key=>$value的标题){ 回显“.$value”。\n”; } //输出每个记录 而($row=$result->fetch_assoc()){ //打印(行); //回声“”; 回音“\n”; //打印数据 foreach($key=>$value的行){ 回显“.$value”。\n”; } 回音“\n”; } 回音“\n”; //没有结果 }否则{ echo“使用SQL:”的零结果$SQL; } }//displayResult()的结尾 ?>_Php_Mysql_Select_Html.dropdownlistfor_Database Table - Fatal编程技术网

Php $sql=“插入场馆(VenuName)” . “价值(“$VICENT。”)”; runQuery($sql,“新记录插入$VICENUE[0]”,true); } $sql=“从与会者中选择*”; $result=$conn->query($sql); displayResult($result$sql); $conn->close(); 函数runQuery($sql、$msg、$echoSuccess){ 全球$conn; //运行查询 if($conn->query($sql)==TRUE){ 如果($echoSuccess){ echo$msg.“成功。”; } }否则{ 使用SQL时回显“错误:“.msg.”使用SQL:“.SQL.”“$conn->错误; } }//runQuery()的结尾 函数displayResult($result$sql){ 如果($result->num_rows>0){ 回音“\n”; //打印标题(字段名称) $heading=$result->fetch_assoc(); 回音“\n”; //将字段名称打印为表标题 foreach($key=>$value的标题){ 回显“$key”。\n”; } 回声“; //打印第一行的值 回声“; foreach($key=>$value的标题){ 回显“.$value”。\n”; } //输出每个记录 而($row=$result->fetch_assoc()){ //打印(行); //回声“”; 回音“\n”; //打印数据 foreach($key=>$value的行){ 回显“.$value”。\n”; } 回音“\n”; } 回音“\n”; //没有结果 }否则{ echo“使用SQL:”的零结果$SQL; } }//displayResult()的结尾 ?>

Php $sql=“插入场馆(VenuName)” . “价值(“$VICENT。”)”; runQuery($sql,“新记录插入$VICENUE[0]”,true); } $sql=“从与会者中选择*”; $result=$conn->query($sql); displayResult($result$sql); $conn->close(); 函数runQuery($sql、$msg、$echoSuccess){ 全球$conn; //运行查询 if($conn->query($sql)==TRUE){ 如果($echoSuccess){ echo$msg.“成功。”; } }否则{ 使用SQL时回显“错误:“.msg.”使用SQL:“.SQL.”“$conn->错误; } }//runQuery()的结尾 函数displayResult($result$sql){ 如果($result->num_rows>0){ 回音“\n”; //打印标题(字段名称) $heading=$result->fetch_assoc(); 回音“\n”; //将字段名称打印为表标题 foreach($key=>$value的标题){ 回显“$key”。\n”; } 回声“; //打印第一行的值 回声“; foreach($key=>$value的标题){ 回显“.$value”。\n”; } //输出每个记录 而($row=$result->fetch_assoc()){ //打印(行); //回声“”; 回音“\n”; //打印数据 foreach($key=>$value的行){ 回显“.$value”。\n”; } 回音“\n”; } 回音“\n”; //没有结果 }否则{ echo“使用SQL:”的零结果$SQL; } }//displayResult()的结尾 ?>,php,mysql,select,html.dropdownlistfor,database-table,Php,Mysql,Select,Html.dropdownlistfor,Database Table,您的具有onchange=“this.form.submit()”,它告诉JavaScript在您进行选择时提交表单。只需删除此项,即可防止表单自动提交。此外,您还希望提交按钮位于之外(实际上根本不需要) 最终,您希望您的如下所示: 选择一个项目 音乐会 阿滕迪 地点 为什么在选择元素上有onchange=“this.form.submit()”。您还有一个提交表单的输入按钮。表单的目的不是让用户选择一个值,然后点击提交按钮吗?这与phpMyAdmin有什么关系?(另外,我希望您没有在每个页

您的
具有
onchange=“this.form.submit()”
,它告诉JavaScript在您进行选择时提交表单。只需删除此项,即可防止表单自动提交。此外,您还希望提交按钮位于
之外(实际上根本不需要)

最终,您希望您的
如下所示:


选择一个项目
音乐会
阿滕迪
地点

为什么在选择元素上有onchange=“this.form.submit()”。您还有一个提交表单的输入按钮。表单的目的不是让用户选择一个值,然后点击提交按钮吗?这与phpMyAdmin有什么关系?(另外,我希望您没有在每个页面视图上删除/创建MySQL表…)我只是尝试使用HTML表单显示我在phpMyAdmin中创建的数据库中的表。出于明显的原因,我没有提供数据库名称。这些代码都与phpMyAdmin无关。phpMyAdmin只是一个编辑MySQL数据库的工具。我正在将您的标签/标题改为
mysql
。好吧,我希望这些表能够被选中并生成到页面中的内容。假设你选择了concert,我想让桌子显示出来,并给你concert_id(PK),和concert。@obsidian之前的代码与我之前的代码做了相同的事情,但是,您的代码格式更吸引人。这是完全不同的。您需要将数据发布到数据库,然后使用该数据库使用PHP输出信息。PHP是服务器端代码,因此无法在页面加载后“更新”页面;你需要JavaScript来实现这一点。您需要做的是使用AJAX将选择发布到生成JSON输出的PHP页面,然后使用JavaScript使用GET查询该页面,将JSON输出存储在变量中,然后解析该JSON客户端。您可以触发所有这些来运行
onchange
。请看。我将上传所有代码,因为我已经在使用PHP了,我只是想从我已经创建的数据库中将带有HTML的数据拉到一个表单中。给我几分钟的时间来编辑代码。为这一混乱道歉。
   <!-- Use JavaScript to automatically submit the selection -->
   <select name="lstDisplay" onchange="this.form.submit()">
      <option value="null">Select an item</option>
      <option value="concert">Concert</option>
      <option value="attendee">Atendee</option>
      <option value="venue">Venue</option>
   </select>
   <!-- set up alternative button in case JavaScript is not active -->
   <noscript>
      <input type="submit" name="btnSubmit" value="View the list" />
      <br /><br />
   </noscript>
   <!-- Use a hidden field to tell server if return visitor -->
   <input type="hidden" name="hidIsReturning" value="true" />
</form>

 // Check connection

        if ($conn->connect_error) {
          die("Connection failed: " . $conn->connect_error);
        }

        // Start with a new database to start primary keys at 1


        $sql = "DROP DATABASE " . DATABASE_NAME;
        runQuery($sql, "DROP " . DATABASE_NAME, true);


        // Create database if it doesn't exist

        $sql = "CREATE DATABASE IF NOT EXISTS " . DATABASE_NAME;

        //if ($conn->query($sql) === TRUE) {
        //  echo "The database " . DATABASE_NAME . " exists or was created succesffuly!<br/>";
        //}

        //else {
        //  echo "Error creating database " . DATABASE_NAME . ": " . $conn->error;
        //  echo "<br/>";
        //}
        runQuery($sql, "Creating " . DATABASE_NAME, false);
        // Select the database

        $conn->select_db(DATABASE_NAME);

        /*
        --------------------------
          * Create the tables
        --------------------------
        */

        // Create Table: volunteer

        /*
                 --------------------------
                   * Create the tables
                 --------------------------
                 */

                 // Create Table: attendee
                 $sql = "CREATE TABLE IF NOT EXISTS attendee (
                         attendee_id    INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                         fName       VARCHAR(20),
                         lName        VARCHAR(20),
                         phone     VARCHAR(15),
                         email           VARCHAR(50)
                 )";
                 runQuery($sql, "Table:attendee", false);

        // Create Table: concert

                 $sql = "CREATE TABLE IF NOT EXISTS concert (
                         concert_id     INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                         concert        VARCHAR(20) NOT NULL
                 )";
                 runQuery($sql, "Table:concert", false);

        // Create Table: attendee_concert

        $sql = "CREATE TABLE IF NOT EXISTS attendee_concert (
                attendee_concert_id   INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                attendee_id           INT(6) UNSIGNED,
                concert_id            INT(6) UNSIGNED,
                paid                  TINYINT(1)
        )";
        runQuery($sql, "Table:attendee_concert", false);

         // Create Table: venue

                 $sql = "CREATE TABLE IF NOT EXISTS venue (
                         venue_id   INT(4) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                         venueName  VARCHAR(25)        
                 )";
                 runQuery($sql, "Table:venue", false);

        /*
                 --------------------------------------------
                 * Populate Tables Using Sample Data attendee
                 * This data will later be collected using a form.
                 --------------------------------------------
                 */
                 // Populate table: attendee

                 $attendeeArray = array(
                   array("Rob", "Nelson", "651-333-3030", "Rob@gmail.com"),
                   array("Matt", "Doe", "888-867-5309", "Matt@gmail.com"),
                   array("Tom", "Reynolds", "651-303-9090", "Tom@gmail.com"),
                   array("Jane", "Doe", "651-678-8901", "Jane@gmail.com"),
                   array("Emily", "Nelson", "612-234-5678", "Emily@gmail.com"),
                   array("Timmy", "Turner", "987-098-0987", "Timmy@gmail.com")
                 );

                 foreach($attendeeArray as $attendee) {
                   echo $attendee[0] . " " . $attendee[1] . "<br/>";
                   $sql = "INSERT INTO attendee (fName, lName, phone, email) "
                           . "VALUES ('" . $attendee[0] . "', '"
                           . $attendee[1] . "', '"
                           . $attendee[2] . "', '"
                           . $attendee[3] . "')";
                   runQuery($sql, "Record inserted for: " . $attendee[0], false);
                 }

         // Populate Table: concert

                 $concertArray = array("Brand New", "Thrice", "Daft Punk", "Kanye West",);

                 foreach($concertArray as $concert) {
                   $sql = "INSERT INTO concert (concert) " . "VALUES ('" . $concert . "')";
                   runQuery($sql, "New record insert $concert[0]", false);
                 }

        // Populate Table: attendee_concert

             $attendee_concertArray = array(
                array(1,1,1),
                array(2,2,1),
                array(3,3,1),
                array(4,3,1),
                array(5,3,1),
                array(6,4,1)
             );

        foreach ($attendee_concertArray as $attendee_concert) {
          $sql = "INSERT INTO attendee_concert (attendee_id, concert_id, paid) "
          . "VALUES ('" . $attendee_concert[0] . "', '"
                           . $attendee_concert[1] . "', '"
                           . $attendee_concert[2] . "')";
          runQuery($sql, "New record insert $attendee_concert[0]", false);
        }


        // Populate Table: venue

                 $venueArray = array("The Myth", "Target Field", "The Cabooze", "Blue Door Pub");

                 foreach ($venueArray as $venue) {
                   $sql = "INSERT INTO venue (venueName) "
                   . "VALUES ('" . $venue . "')";
                   runQuery($sql, "New record insert $venue[0]", true);
                 }

                 $sql = "SELECT * FROM attendee";
                 $result = $conn->query($sql);
                 displayResult($result, $sql); 
                 $conn->close(); 

                 function runQuery($sql, $msg, $echoSuccess) {

                   global $conn;

                   // run the query
                   if ($conn->query($sql) === TRUE) {
                      if($echoSuccess) {
                         echo $msg . " successful.<br/>";
                      }
                   } else {
                      echo "<strong>Error when: " . $msg . "</strong> using SQL: " . $sql . "<br/>" . $conn->error;
                   }

                 } // end of runQuery()


        function displayResult($result, $sql) {

          if ($result->num_rows > 0) {
            echo "<table border='1'>\n";
            // print headings (field names)
          $heading = $result->fetch_assoc( );
          echo "<tr>\n";
          // Print field names as table headings
          foreach($heading as $key=>$value){
             echo "<th>" . $key . "</th>\n";
          }
          echo "</tr>";
          // Print the values for the first row
          echo "<tr>";
          foreach($heading as $key=>$value){
             echo "<td>" . $value . "</td>\n";
          }
              // Output each record
              while($row = $result->fetch_assoc()) {
                //print_r($row);
                //echo "<br />";
                echo "<tr>\n";
                // print data
                foreach($row as $key=>$value) {
                   echo "<td>" . $value . "</td>\n";
                }
                echo "</tr>\n";
            }
            echo "</table>\n";
          // No results
          } else {
             echo "<strong>zero results using SQL: </strong>" . $sql;
          }


        } // end of displayResult( )

         ?>