Jump to content

Get category name.....


Skarabeol

Recommended Posts

Here is posts.php

<?php include('includes/functions.php'); ?>
<html>
<head>
<title>Basic CMS- Admin Area</title>
</head>
<body>
<a href="logout.php">Logout</a>
<a href="posts.php">Manage Posts</a>
<table cellspacing="0" cellpadding="10">
<thead>
<tr>
	<td>Post Title</td>
	<td>Author</td>
	<td>Category</td>
	<td>Action</td>
</tr>
</thead>
<tbody>
<?php getPosts(); ?>
</tbody>
</table>

</body>
</html>

 

Here is a part of functions.php

<?php
include('includes/connect.php');

function getPosts() {
$query = mysql_query("SELECT * FROM posts") or die(mysql_error());
if(mysql_num_rows($query) == 0) {
		echo "<tr><td colspan=\"3\">No Posts Where found</td></tr>";
} else {
		while($post = mysql_fetch_assoc($query)) {
		echo "<tr><td>" . $post['Title'] . "</td><td>" . $post['Author'] . "</td><td>" . $post['category_id'] . "</td><td><a href=\"delete.php?id=" . $post['ID'] . "\">Delete</a><br /><a href=\"edit.php?id=" . $post['ID'] . "\">Edit</a></td></tr>";
	}
}
}

 

 

Table posts

ID

Title

Author

Content

category_id

 

Table categories

IDNameDescription

 

 

 

When i access posts.php it shows me that:

categoryproblem.png

 

 

I want to display me there the name of category wich has the ID = with category_id from posts table :)

Link to comment
https://forums.phpfreaks.com/topic/234505-get-category-name/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.