[code=php]<?php // let’s go!
// get the news!
$postID = $_GET[‘postID’];
$title = $_GET[‘title’];
// make sure that GET is set
if (!isset($_GET[‘postID’]) || !isset($_GET[‘title’]))
{
// if not, display an error
die(‘There is no data.’);
}
// require the connection and formatting settings
require_once(“path_to_connection”);
require_once(“path_to_code”);
// set up the access
$conn = dbAccess();
$query1 = “SELECT `a`.`post_id`, `a`.`user_id`, `a`.`author_id`, `a`.`author_name`, `a`.`date_posted`, `a`.`author_email`, `a`.`category_id`, `c`.`category_name`, `a`.`title`, `a`.`post_body`, `a`.`tags`, `a`.`info` FROM `posts` `a` INNER JOIN `categories` `c` ON `a`.`category_id` = `c`.`category_id` WHERE `a`.`post_id` = ? AND `a`.`title` = ? LIMIT 1”;
if ($stmt1 = $conn->prepare($query1))
{
// bind the parameters
if ($stmt1->bind_param(‘is’, $newID1, $newTitle1))
{
$newID1 = $postID;
$newTitle1 = $title;
if ($stmt1->execute())
{
// bind the result
if ($stmt1->bind_result($postIDNULL, $userIDNULL, $authorIDNULL, $authorNULL, $dateNULL, $emailNULL, $catIDNULL, $category, $newsTitle, $bodyNULL, $newsTags, $newsInfo))
{
if ($stmt1->fetch())
{
?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title><?php echo $newsTitle . ” — Ultimate Hogwarts: The Rebirth”; ?></title>
<link href=”/css/general2.css” rel=”stylesheet” type=”text/css”>
<link href=”/css/ulists.css” rel=”stylesheet” type=”text/css”>
<link href=”/css/test.css” rel=”stylesheet” type=”text/css”>
<meta name=”keywords” content=”<?php echo $newsTags; ?>”>
<meta name=”description” content=”<?php echo $newsInfo; } } } } $stmt1->close(); } ?>”>
<?php // include the remaining meta information
include_once(“../includes/meta_info.html”);
?>
</head>
<body>
<div id=”wrapper”>
<div id=”headers”>
<div id=”header1″></div>
<div id=”header2″></div>
</div>
<div id=”navigation”>
<!– Begin Navigation Menu –>
<?php // include the navigation menu
include_once(“../includes/navigation2.html”); ?>
<!– End Navigation Menu –>
</div>
<div id=”right”>
<p>Hello!</p>
</div>
<div align=”center” id=”center”>
<div id=”news”>
<?php
// write the query
// REMEMBER JEFFREY: WHEN USING INNER JOIN IN A SQL QUERY, BOTH THE MYSQL FIELD AND PREFIX NEED TO BE TICKED AND DOTTED, AS SO: `a`.`username`
$query2 = “SELECT `a`.`post_id`, `a`.`author_id`, `a`.`author_name`, DATE_FORMAT(`a`.`date_posted`, ‘%W, %M %d %Y %l:%i %p’), `a`.`author_email`, `a`.`category_id`, `c`.`category_name`, `a`.`title`, `a`.`post_body` FROM `posts` `a` INNER JOIN `categories` `c` ON `a`.`category_id` = `c`.`category_id` WHERE `a`.`post_id` = ? AND `a`.`title` = ? LIMIT 1”;
if ($stmt2 = $conn->prepare($query2))
{
if ($stmt2->bind_param(‘is’, $newID2, $newTitle2))
{
$newID2 = $postID;
$newTitle2 = $title;
if ($stmt2->execute())
{
// bind the results
if ($stmt2->bind_result($post_id, $author_id, $author, $date, $email, $catID, $category, $newNewsTitle, $body))
{
if ($stmt2->fetch())
{
$body = html_entity_decode($body, ENT_QUOTES, ‘UTF-8’);
echo “<div class=’news’><b>$newNewsTitle</b></div>”;
echo “<div class=’news’><b>Posted By:</b> $author on $date in $category</div>”;
echo “<div class=’news_post’>” . BBCODE(strip_tags($body, ‘<p><br><a><b><i>’)) . “</div>”;
}
}
}
}
$stmt2->close();
}
$conn->commit();
$conn->close();
?>
</div>
</div>
</div>
</body>
</html>
If there is a more efficient way of getting the first set of data out, I would like to know. All I need is to get the title, tags, and info out for SEO purposes, but it doesn’t seem to work unless I pull all of the data from the database. Would this code:
[code=php]$query = “SELECT `title`, `tags`, `info` FROM `posts` WHERE `post_id` = ? AND `title` = ? LIMIT 1”;
work? I just want to make sure I’m trying the right thing before I go into debugging.