仅基于Session变量尝试在日记帖子页中显示此数据。
Session变量已在php /函数文件中声明。
数据外键已经在帐户表中的用户ID和PHP my admin中的日记帐表之间链接起来
我只需要一些说明的内部联接查询,即可仅显示基于会话的数据。
在日记页面顶部声明的功能
<?php
include("php/functions.php");
$userID = $_SESSION["userID"];
?>
功能文件
<?php
if(session_id() == '') {
session_start();
}
if(!isset($_SESSION['myEmail'])){ //if login in session is not set
header("Location: login.php");
}
if (!isset($_SESSION['myEmail'])) {
echo" <a href='login.php'";
}
else {
$myFName = $_SESSION['userFirstName'];
}
我需要在其中显示基于Session变量的帖子
<?php
// index.php
include 'mysql.php';
echo '<h1>My Positive Experience Diary</h1>';
echo "<em>Post 10 Positive Recent Experiences</em><hr/>";
$result = mysql_safe_query('SELECT * FROM posts ORDER BY date DESC');
if(!mysql_num_rows($result)) {
echo 'No posts yet.';
} else {
while($row = mysql_fetch_assoc($result)) {
echo '<h2>'.$row['title'].'</h2>';
$body = substr($row['body'], 0, 300);
echo nl2br($body).'...<br/>';
echo '<a href="post_view.php?id='.$row['id'].'">Read More</a> | ';
echo '<hr/>';
}
}
echo <<<HTML
<a href="post_add.php">+ New Post</a>
HTML;
?>
在diarypost页面上获取数据的mysql.php。
<?php
// mysql.php
function mysql_safe_string($value) {
$value = trim($value);
if(empty($value)) return 'NULL';
elseif(is_numeric($value)) return $value;
else return "'".mysql_real_escape_string($value)."'";
}
function mysql_safe_query($query) {
$args = array_slice(func_get_args(),1);
$args = array_map('mysql_safe_string',$args);
return mysql_query(vsprintf($query,$args));
}
function redirect($uri)
{
if (!headers_sent())
{
header('Location: '.$uri);
exit;
}
else
{
echo '<script type="text/javascript">';
echo 'window.location.href="'.$uri.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$uri.'" />';
echo '</noscript>'; exit;
}
}
@mysql_connect('localhost','########','########');
@mysql_select_db('########');
看起来不是基于用户ID来发布数据库中的所有数据的样子