Jump to content

MySQL, 2 tables


devknob

Recommended Posts

I have 2 tables, one of them is 'friends' another is 'users'

 

I need to pull * from friends and attach 1 corresponding column from the users table to identify a picture.

 

Tried this $sql = "SELECT msgs.pid, msgs.uid, msgs.run, users.di FROM msgs,users WHERE msgs.pid='$id'";

but thats doing some strange stuff.. any ideas?

Link to comment
Share on other sites

Strange stuff being the wrong images listed several times

 

Here is the php

 

<?
//CHECK FOR FRIENDS
include('connection.php');
$sql = "SELECT msgs.pid, msgs.uid, msgs.run, users.di FROM msgs,users WHERE msgs.pid='$id'";
$rs = mysql_query($sql,$conn);      
$numfr = mysql_num_rows($rs);
?>
      <tr>
        <td bordercolor="#000000" bgcolor="#E0DFE3" class="style5">  <?php print $ftit; ?> 
          , Showing <? print $numfr; ?> <span class="style1">- <a href="#">View All</a></span></td>
        </tr>
      <tr>
        <td bordercolor="#000000" bgcolor="#FFFFFF" class="style5"></td>
      </tr>
    </table>

<?
while($row = mysql_fetch_object($rs)){
$pid = $row->pid;
$usr = $row->uid;
$img = $row->di;
$usrna = $row->run;

if($usr != 0){
if($img == 0){ $img = 1; }
print "<a href=\"profile.php?id=$usr\"><img src=\"pix/tn/$img.jpg\"><br>" . $usrna . "</a>"; 
$img = 0;
}
}

 

Heres the tables

 

msgs (this is where friends are)

id|pid|uid|run

 

users (this is where the img number is)

id|userdata|di|

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.