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
https://forums.phpfreaks.com/topic/251454-mysql-join/
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
https://forums.phpfreaks.com/topic/251454-mysql-join/#findComment-1289629
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.