I'm building a blog and to view each post I use:
post.php?id=<?php echo $row_post['id']; ?>
Post is a table in my db.
$colname_post = "-1";
if (isset($_GET['postid'])) {
$colname_post = $_GET['postid'];
}
mysql_select_db($database_connect, $connect);
$query_post = sprintf("SELECT postid, title, DATE_FORMAT(date,'%%d.%%m.%%Y') AS date, idcategory, text FROM post WHERE postid = %s", GetSQLValueString($colname_post, "int"));;
$post = mysql_query($query_post, $connect) or die(mysql_error());
$row_post = mysql_fetch_assoc($post);
$totalRows_post = mysql_num_rows($post);
I've got a problem displaying data that is not in the post table. For example under the title, I want to display the category. Category is a separate table. The relation between them is that one category can be connected to many posts, but one post can only have one category. They are connected with categoryID (foreign key). Comment if you need to see show create table
.
So, while all the data from the post table is correctly displayed, the data from other tables (that is the tables which do not include postid as an attrubute) are not. For example
<h1><?php echo $row_post['title']; ?></h1> <-- correct value displayed
<p><?php echo $row_category['name']; ?></p> <-- not correct
Any suggestions for how to fix this?