[英]Return one value from SQL database using PHP
just wondering is there any way that I can return one value from my SQL database? 只是想知道有什么方法可以从SQL数据库返回一个值? Basically I am writining a website for my A level ICT coursework.
基本上,我正在为我的A级ICT课程编写网站。 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 http://gyazo.com/a8cfda3735c8bf2fd26b3b1c70fab191
Hopefully this generates a better understanding of my problem. 希望这能更好地理解我的问题。
Thanks 谢谢
Alex. 亚历克斯
instead of WHERE description=description
you need to put something like WHERE id=$someid
. 而不是
WHERE description=description
您需要输入WHERE id=$someid
。 this way you grab only the record matching a certain primary key id field. 这样,您仅获取与某个主键id字段匹配的记录。 you would want to pass $someid to the page via a GET variable in the link most likely.
您最有可能希望通过链接中的GET变量将$ someid传递给页面。 you could also ad
LIMIT 1
at the end to make sure the query only grabs one. 您还可以在广告末尾添加
LIMIT 1
,以确保查询只能抓取一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.