Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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/3/html/90.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生成的html表的样式_Php_Html_Css_Html Table_Dynamically Generated - Fatal编程技术网

设置用php生成的html表的样式

设置用php生成的html表的样式,php,html,css,html-table,dynamically-generated,Php,Html,Css,Html Table,Dynamically Generated,所以我有这个html表格,我想样式。它包含php,为表提供其值(这是一组选择字段) 我可能做错了什么,php可以正常工作(它将数据发送到我的数据库),但我不能用css设置样式 <form action='processes.php' method='GET'> <table> <?php echo "<tr>"; echo "<th>COURSE NUMBER</th>";

所以我有这个html表格,我想样式。它包含php,为表提供其值(这是一组选择字段)

我可能做错了什么,php可以正常工作(它将数据发送到我的数据库),但我不能用css设置样式

<form action='processes.php' method='GET'>
    <table>
        <?php
        echo "<tr>";
        echo "<th>COURSE NUMBER</th>";

        foreach($course_list as $cc){
            $c = str_replace("_", " ", $cc);
            echo "<th>$c</th>";
        }

        echo "</tr>";  

        while($record = mysqli_fetch_assoc($user_subject_results)){

            echo "<tr>";                
            $subjects[] = $record['Course']; //stores every subject in a list
            $_SESSION['Subjects'] = $subjects; //store the list in a session variable so i can use it in my processes page.             
            echo "<td>".$record['Course']."</td>";  

            foreach($course_list as $cc){

                echo "<input type = 'hidden', name = ".'pk'.$record['Course']." value = ".$user.'_'.$record['Course']." />";                    
                echo "<td><select name =".$kc.$record['Course'].">";                    

                foreach($eval_list as $opt){
                    echo "<option value = '".$opt."'>".$opt."</option>";
                }

                "</select>
                </td>";
            }

            echo "</tr>";
        }
        ?>
    </table>
    <input type='submit' value='submit' />
</form>

好吧,老实说,我会先把表换成div标签。现在这只是我,但这使它更容易风格。以下是我将如何开始的示例:

外部样式表Style.css

    #main-div{
        /*All Your styles Go Here if you dont know how to style refer to w3schools.org*/

    }

    .header{
        /*All Your styles Go Here if you dont know how to style refer to w3schools.org*/

    }

    .courses-head{
        /*Give this a width such as width:10%; or 20% or whatever 
        example:
        width:20%;
        Add more styles if necessary
        */
    }

    .courses-list{
        /*Give this a width such as width:10%; or 20% or whatever 
        example:
        width:20%;
        Add more styles if necessary
        */
    }
您的实际页面:

<!--This goes in the Head -->
    <link rel="stylesheet" href="/path/to/styles.css">

    <form action='processes.php' method='GET'>
        <div id=main-div>
            <?php
            echo "<div class='header'>";
            echo "<div class=courses-head>COURSE NUMBER</div>";

            foreach($course_list as $cc){
                $c = str_replace("_", " ", $cc);
                echo "<div class='course-list'>$c</div>";
            }

            echo "</div>";  


html元素上没有样式定义或css类。你的CSS在哪里?刚刚添加的!抱歉,我真的是个新手,html属性中
=
两边的空格不是把一切都搞糟了吗?@Zyigh不,不是。你的PHP创建了无效的html。您缺少一个
,因此输入不在表格单元格内。另外,你有一个文本“”,前面没有回声。是的,我想我会这样做。看起来容易多了。谢谢相信我说的话,你会节省很多时间。此外,如果您在学习如何使用样式表或文档标记方面需要任何帮助,那么学校将提供大量关于如何使用它们的教程。
<!--This goes in the Head -->
    <link rel="stylesheet" href="/path/to/styles.css">

    <form action='processes.php' method='GET'>
        <div id=main-div>
            <?php
            echo "<div class='header'>";
            echo "<div class=courses-head>COURSE NUMBER</div>";

            foreach($course_list as $cc){
                $c = str_replace("_", " ", $cc);
                echo "<div class='course-list'>$c</div>";
            }

            echo "</div>";