Jump to content

MySql JOIN


richiejones24

Recommended Posts

I am trying to join these 2 tables below, but its not working, any ideas where i am going wrong??

<?php
require("../include/mysqldb.php");
$con = mysql_connect("$dbhost","$dbuser","$dbpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$dbame", $con);



$result = "SELECT *
Reg_Profile_public.pref, Search_profiles_up.search_small_image
FROM
Search_profiles_up
INNER JOIN
Reg_Profile_public
ON
Search_profiles_up.UIN=Reg_Profile_public.UIN
WHERE
UIN='803272125132009'";

while ($row = mysql_fetch_array($result)) {
    echo $row['search_small_image'];
    echo $row['pref'];
}



?>

Link to comment
Share on other sites

I don't know your table structure, but you have an error in your SELECT statement. It should be:

 

SELECT * FROM table... or SELECT col1, col2 FROM table

 

Also, you can use the AS keyword to give the table an alias, as in: search_profiles AS sp. You can even omit it, as in: search_profiles sp, but personally I recommend it as it makes the code more readable. I would write your query like below:

 

SELECT reg.pref, search.search_small_image
FROM search_profiles_up AS search
INNER JOIN reg_profile_public AS reg
USING (uin)
WHERE uin='803272125132009';

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.