使用PHP从SQL数据库返回一个值

just wondering is there any way that I can return one value from my SQL database? Basically I am writining a website for my A level ICT coursework. The website must allow posts to be made users and these posts must be stored in a table and then can be viewed by clicking on them So far I have created a registration form and log in script to authenticate the session and delegate permission levels to users, I have created scripts which post threads to my database and have another script in place to store the data in the table Now I wish to be able to view my posts when I click on them So far my script is as follows

    <?php include_once('scripts/session_a.php') ; ?>
<?php include_once('scripts/connection.php') ; ?>


<?php


            $strSQL = "SELECT description FROM posts WHERE description=description";
            $result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
            $row = mysql_fetch_assoc($result);

            echo $row['description'];


?>

and this script is called from

   <!--////////////////////////////////////////////////////////
    // Project : Absolute Beginners log in system ///////////
    // Purpose : A2 Level Coursework for ICT ////////////////
    // Teacher : Mr L Hawkins ///////////////////////////////
    // Student : Alex Sims //////////////////////////////////
    // Candidate No. : 4173 /////////////////////////////////
    // Centre No : 27168 ////////////////////////////////////
    /////////////////////////////////////////////////////////-->

    <?php include_once('includes/header.php') ; ?>
    <?php include_once('includes/posts-header.php') ;?>

    <div> <!-- Main Wrapper -->
        <div class="Post Head"/><!-- Start Page -->
            <name="Post" id="Post"/>
            <h2>Absolute Beginners Forum</h2>




        <div name="postname" id="postname"/>    <!--PHP SCRIPT FEEDS NAME DATE AND AUTHOR HERE -->
                <label></label>

                <?php include('scripts/echo_test.php');?>

        </div>


        <div name="content" id="content"/>     <!-- PHP SCRIPT FEEDS CONTENT HERE -->

                <?php include('scripts/get_post_content.php')?>

        </div>

    </div><!-- End board-->







</div><!--End of page-->






</div> <!-- Main Wrapper Ends -->
<?php

a screenshot can be seen here of what I was trying to describe

http://gyazo.com/a8cfda3735c8bf2fd26b3b1c70fab191

Hopefully this generates a better understanding of my problem.

Thanks

Alex.

php
du229908
du229908 你能澄清一下你想做什么吗?是否要显示登录用户创建的所有帖子或其他内容?另外,我们可以看看你的桌子结构。
接近 9 年之前 回复

1个回答



而不是 WHERE description = description </ code>你需要输入像 WHERE id = $ someid < /代码>。 这样,您只能获取与某个主键ID字段匹配的记录。 您可能希望通过链接中的GET变量将$ someid传递给页面。 您也可以在结尾处添加 LIMIT 1 </ code>,以确保查询只获取一个。</ p>
</ div>

展开原文

原文

instead of WHERE description=description you need to put something like WHERE id=$someid. this way you grab only the record matching a certain primary key id field. you would want to pass $someid to the page via a GET variable in the link most likely. you could also ad LIMIT 1 at the end to make sure the query only grabs one.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐