PHP文章录入数据库后如何正确显示出来

PHP文章录入数据库后如何正确显示出来 本人的代码如下
<?php require_once('../Connections/myconn.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO inform (title, subtitle, content, typist) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['subtitle'], "text"),
GetSQLValueString($_POST['content'], "text"),
GetSQLValueString($_POST['typist'], "text"));

mysql_select_db($database_myconn, $myconn);
$Result1 = mysql_query($insertSQL, $myconn) or die(mysql_error());

$insertGoTo = "inform.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>

require_once('../Connections/myconn.php');/*你这个应该已经连接了数据库了,如果没有就自己再连接一次*/
$sql="SELECT * FROM ($datebase_myconn)";/**查询你的数据库里面的内容的语句**/
$query=mysql_query($sql);/**把查询语句执行**/
while($show=mysql_fetch_array($query))/**遍历数据库里的条数**/
{
echo $show['title'];/*这里你可以插入到html的里面,echo的内容是你的数据库里面的内容,title可以换成subtitle, content什么的,就看你的数据是什么了*/
}
mysql_close($myconn);//有打开就有关闭^_^
显示文章的数据库内容,简单的就是把你的写入数据的内容改成查找,然后读出来而已
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-01-14
mysql_fetch_row

mysql_fetch_array
用法查阅手册

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网