php / mysql选择id = url id的位置

时间:2015-03-13 20:42:22

标签: php mysql

我的脚本有问题。我有一个项目页面,如果你点击你的一个项目(这是用户的项目列表),你可以转到项目页面,其中包含project.php?project = id。

项目划分:

                <?php
            require_once 'core/init.php';
            include("header.php");

            ?>

            <?php
            $project = DB::getInstance()->query("SELECT * FROM projects WHERE user_id = '" . $_SESSION['user'] . "' ");
            $project_item = new Projectitem();

            if(!$project->count()) {
                echo 'No Projects';
            } else {

                ?>
                <div class="table-responsive">
                <table class="table table-bordered">
                <?php
                foreach($project->results() as $project) {

                echo "<tr>";?>
                <td width="9,375em"><img src="<?php echo $project->project_img; ?>"><?php
                echo "</td>";
                echo "<td>";?>   


                <a href="project_item.php?project=<?php echo escape($project->id); ?>"><?php echo escape($project->name); ?></a>

                <?php
                echo "</td>";
                echo"</tr>";
                }
            }

            echo "</table>";
            echo "</div>";

            include("footer.php");
            ?>

如果您在ID为3的项目上单击作为exmplain,您将获得下一个结果:

project_item.php?项目= 3

项目页面脚本:

            <?php
        require_once 'core/init.php';
        include("header.php");

        ?>

        <?php
        $project = DB::getInstance()->query("SELECT * FROM projects  WHERE id = ? ");

        if(!$project->count()) {
            echo 'No Projects';
        } else {

            ?>
            <div class="table-responsive">
            <table class="table table-bordered">
            <?php
            foreach($project->results() as $project) {

            echo "<tr>";?>
            <?php echo "<td>";?>   


            <?php echo escape($project->name); ?>

            <?php
            echo "</td>";
            echo"</tr>";
            }
        }

        echo "</table>";
        echo "</div>";

        include("footer.php");
        ?>

如何通过查询获得正确的项目?

SELECT * FROM projects  WHERE id = ? //(the id from the url)

0 个答案:

没有答案