Jump to content

Replacing a userid with a username from another table


BustahBrown

Recommended Posts

I've got this code to display the latest created article. In my users table i've got "id" which is the primary key, first name, last name, username and password. In my articles table i've got article id, user id, category, title, content, cover, bigcover and date. I've got the article displaying everything it needs to, however where it's got ".$row1['userid']." in the content1date div, i would like it to display the username from the users table. (id from the users table and userid from the articles table is the relation)

 

  <?php

  $article1 = mysql_query("SELECT * FROM articles ORDER BY id DESC LIMIT 0, 1");

 

while ($row1 = mysql_fetch_assoc($article1))

{

 

  echo "

  <div id='content1image'><img src='upload/".$row1['cover']."' /></div>

<div id='content1title'><font size='5' face='verdana'><i>".$row1['title']."</i></font></div>

<div id='content1date'><font size='2' face='verdana'>Posted in <b><a href=''>".$row1['category']."</a></b> by <b><a href=''>".$row1['userid']."</a></b> on ".$row1['date']."</font></div>

<div id='content1'><font size='2' face='verdana'>".$row1['content']."</font></div>

<div id='sub1'><font face='Verdana' size='5'><i>".$row1['title']."</i></font></div>

";

}

?>

 

There's probably some really simple solution, unfortunately i'm fairly new to PHP, any help would be awesome, thanks :D

Ah thanks, yeah i figured it was something like this, i've tried sticking in some joins, but honestly not where where to stick them in (if it's in my while statement where i think it should go it stuffs up) So anyone that's good with joins, would be muchly appreciated!

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.