php - 用 php 数据库中的数据填充组合框

标签 php database combobox

这是我的代码

    <select>
        <?php
        $query = "SELECT * FROM 'sections'";
        $result = mysql_query($query);  
            while($row=mysql_fetch_array($result)){                                                 
            echo "<option value='".$row[id]."'>".$row[sectionName]."</option>";
            }
        ?>          
    </select>

什么都没有发生我不知道为什么 这个我的页面可能有些地方不对

<?php
    ob_start();
    session_start();
    include('../includes/connect.php');
    include('../includes/phpCodes.php');        

?>

<!DOCTYPE html>
<html>
    <head>
        <title>لوحة التحكم</title>
        <meta charset="utf-8">

        <link rel="stylesheet" type="text/css" href="../css/mainstyle.css">
        <link rel="stylesheet" type="text/css" href="css/controlstyle.css">
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $('#tabs div').hide();
                $('#tabs div:first').show();
                $('#tabs ul li:first').addClass('active');
                $('#tabs ul li a').click(function(){ 
                    $('#tabs ul li').removeClass('active');
                    $(this).parent().addClass('active'); 
                    var currentTab = $(this).attr('href'); 
                    $('#tabs div').hide();
                    $(currentTab).show();
                    return false;
                });
            });
        </script>
    </head>
    <body>
    <div class="wrapper">
        <?php headerCode(); ?>
        <div class="content">
              <div id="tabs">
                <ul>
                    <li><a href="#add">اضافة موضوع</a></li>
                    <li><a href="#remove">حذف موضوع</a></li>
                    <li><a href="#edit">تعديل موضوع</a></li>
                    <li><a href="#edit">التحكم بالاقسام</a></li>
                </ul>
                <div id="add">
                    <form method="POST" action="includes/add.php" dir="rtl" enctype="multipart/from-data">
                        <br>
                        حدد القسم :
                        <select>

                                    <?php
                                    $query = "SELECT * FROM 'sectionsd'";
                                    $result = mysql_query($query);
                                    while($row=mysql_fetch_array($result)){
                                        echo "<option value='".$row[id]."'>".$row[sectionName]."</option>";
                                    }?>         
                        </select><br>
                        عنوان الموضوع :<input type="text" name="title" class="mem-information"/><br>
                        الموضوع : <br /><textarea name="subject" rows="10" cols="50" class="mem-information" style="width: 500px"></textarea><br /><br>
                        الصورة :<input type="file" name="image"><br>
                        <input type="submit" value="إرسال" name="send" class="log" style="color: black">
                    </form>
                </div>
                <div id="remove">
                    <form method="POST" action="includes/remove.php" dir="rtl"><br>
                    حدد القسم :
                    <select name ="sectionsName">
                    <option value="">dd</option>
                    </select>

                        <input type="submit" value="حذف" name="send" class="log" style="color: black">
                    </form>
                </div>
                <div id="edit">

                </div>
                <div id="addDep">

                </div>
            </div>
        </div>
    </div>
    </body>
</html>

抱歉我的英语不好 我的 table enter image description here

最佳答案

我看到的问题是您在查询中对表名使用了单引号,您应该为表名使用反引号或不使用反引号。请尝试以下代码:

<?php
    $query = "SELECT * FROM `sections`";
    $result = mysql_query($query);
    while($row=mysql_fetch_array($result, MYSQL_ASSOC)){                                                 
       echo "<option value='".$row['id']."'>".$row['sectionName']."</option>";
    }
?>

同时开始考虑使用 mysqli ( http://php.net/manual/en/book.mysqli.php ) 或 PDO ( http://php.net/manual/en/book.pdo.php ),因为 mysql 已被弃用。

关于php - 用 php 数据库中的数据填充组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17930312/

相关文章:

php - 开发网络应用程序

sql - 如何在 Oracle 连接中仅查询非系统数据库?

database - Google datastore 的 "Highly Scalable"属性到底是什么意思?

Mysql:如何处理具有数百万行的表?

css - Bootstrap 3 组合框在移动 View 中停止工作

php - 如何预配YouTube网址和YouTube短网址并从中获取视频ID php

php - "laravel.log"无法打开 : failed to open stream

php - 具有多个存储后端的 CMS

wpf - 自定义 WPF ComboBox 不显示分组

wpf - 设置 ComboBox 选中项高亮颜色