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
https://forums.phpfreaks.com/topic/58924-mysql-2-tables/
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
https://forums.phpfreaks.com/topic/58924-mysql-2-tables/#findComment-292429
Share on other sites

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.