Jump to content

how do I display values from another mysql table?


Darkwoods
 Share

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.