douzhang1926 2011-10-29 21:35
浏览 68
已采纳

使用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.

  • 写回答

1条回答

  • dougua3706 2011-10-29 22:34
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料