Jump to content

MYSQL & php arraying?


charliepoo

Recommended Posts

Yes I did just turn array into a verb :P

I'm going to sound really noobish right now, but anyway I'm working with FanUpdate and I'm trying to display a list of the posts in a category by a link, so that on the navigation bar I don't have to keep adding every time a post gets added.

This is what I have so far:

<?php
mysql_select_db("charioti_hive", $con);

$result = mysql_query("SELECT * FROM blog_catjoin
WHERE cat_id='8'");

while($row = mysql_fetch_array($result))
  {
  echo "<a href=/activities.php?id=" . $row['entry_id'] . " class=n>";
  }
mysql_close($con);
?> 

So that loads obviously, all the entry_ids which are in category 8 and displays the link. This all works - what I'm wanting to do is query another table using these entry IDs so that I can get the entry names, so that instead of displaying "link" each time it displays the entry's actual name. Guessing it's fairly simple, but I've looked it up in my php book and I've googled it and can't find a tutorial that is simple enough for a dummy like me.

Any help or even hints to where to go from here would be appreciated.

Link to comment
Share on other sites

Try:

 

$query = "SELECT a.entry_id, b.title FROM blog_catjoin as a, blog as b
WHERE (a.entry_id = b.entry_id) AND a.cat_id='8'";

$result = mysql_query($query) or die($query . ' <br /> ' . mysql_error());

while($row = mysql_fetch_array($result))
  {
  echo "<a href=/activities.php?id=" . $row['entry_id'] . " class=n>" . $row['title'] . '</a><br />' . "\n";
  }
mysql_close($con);
?> 

 

And let us know how it goes...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

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