Skarabeol Posted April 23, 2011 Share Posted April 23, 2011 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: 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 More sharing options...
zander1983 Posted April 23, 2011 Share Posted April 23, 2011 you need to join the tables select p.*, c.Name from posts p join categories c on (c.ID = p.category_id) then replace $post['category_id'] with $post['Name'] Link to comment https://forums.phpfreaks.com/topic/234505-get-category-name/#findComment-1205225 Share on other sites More sharing options...
Skarabeol Posted April 23, 2011 Author Share Posted April 23, 2011 Thank you very much!You helped me a lot:) Link to comment https://forums.phpfreaks.com/topic/234505-get-category-name/#findComment-1205262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.