Darkwoods Posted July 13, 2011 Share Posted July 13, 2011 Hey I'm trying to display the names of the categories but the values are numbers connected to another table with the title of the category and the other problem is that sometimes it is multi categories selected and this will make a value like 1,2 so how can I solve this please? here is my messed up code and there seems to be something wrong with it.. <?PHP $result = mysql_query("SELECT * FROM properties, categories ",$connect); while($row = mysql_fetch_assoc($result)) { $pr_category = $row["pr_category"]; ?> <h2><a href="blog-post.html"><?php echo $row['pr_title']; ?></a></h2> <?PHP $result = mysql_query("SELECT * FROM categories WHERE id='$pr_category' ",$connect); while($row = mysql_fetch_assoc($result)) { $cat_title = $row["title"]; ?> <p class="date">12 July 2011 in <a href="#"><?php echo $cat_title; } ?></a></p> <img class="img-large-bg" src="../uploads/images/<?php echo $row['f_img']; } ?> Link to comment https://forums.phpfreaks.com/topic/241935-how-do-i-display-values-from-another-mysql-table/ Share on other sites More sharing options...
teynon Posted July 13, 2011 Share Posted July 13, 2011 SELECT * FROM properties INNER JOIN categories WHERE categories.id = properties.id AND categories.id IN ($value) I think, might need some work. I'm in pain and medicated. Link to comment https://forums.phpfreaks.com/topic/241935-how-do-i-display-values-from-another-mysql-table/#findComment-1242475 Share on other sites More sharing options...
jcbones Posted July 14, 2011 Share Posted July 14, 2011 Try running: SELECT a.*, b.title FROM properties AS a JOIN categories AS b ON a.pr_category = b.id I would suggest running that query inside your database management software (phpMyAdmin), or the console, to make sure it returns the data you expect. This will save you coding time. Link to comment https://forums.phpfreaks.com/topic/241935-how-do-i-display-values-from-another-mysql-table/#findComment-1242546 Share on other sites More sharing options...
Darkwoods Posted July 14, 2011 Author Share Posted July 14, 2011 Try running: SELECT a.*, b.title FROM properties AS a JOIN categories AS b ON a.pr_category = b.id I would suggest running that query inside your database management software (phpMyAdmin), or the console, to make sure it returns the data you expect. This will save you coding time. Hey your code worked but my remaining problem is how do I display the name of multi categories for example in the mysql field I got 1,2 which are cat1 and cat2 so far I'm only seeing the name of one category Link to comment https://forums.phpfreaks.com/topic/241935-how-do-i-display-values-from-another-mysql-table/#findComment-1242619 Share on other sites More sharing options...
jcbones Posted July 14, 2011 Share Posted July 14, 2011 What mysql field? How can a property be in two different categories? Perhaps you need a table to tie multiple categories to the one property. Has your database been normalized? If not, I would suggest reviewing some short video's. This will go along way in helping you to get data in an ordered, and dependable fashion. <-Watch all 9, they are short, shouldn't take you to long. Link to comment https://forums.phpfreaks.com/topic/241935-how-do-i-display-values-from-another-mysql-table/#findComment-1242872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.