Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2017
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying to use aliases within a inner join query in PHP

    $query = "(SELECT * FROM wine a INNER JOIN manufacturer b ON a.manufacturer_manufacturer_id = b.manufacturer_id INNER JOIN region c ON a.manufacturer_region_id = c.region_id INNER JOIN grape_variety d ON a.grape_variety_grape_id = d.grape_id)";

    This was my original query to pull all the data from my db but as the names of the manufacturers, wines and regions are called 'name' in the SQL tables I need to put aliases in to pull out the correct data for each name.

    //loop through selected table
    while($row = mysql_fetch_array($data_wine, MYSQL_BOTH))
    {
    $data .= '<item>';
    //$data .= '<ID>' .(utf8_encode($row['wine_id'])). '</ID>';
    $data .= '<wine_name>' .(utf8_encode($row['name'])). '</wine_name>';
    //$data .= '<type>' .(utf8_encode($row['type'])). '</type>';
    //$data .= '<alcohol_percentage>' .(utf8_encode($row['alcohol_percentage'])). '</alcohol_percentage>';
    //$data .= '<winecol>' .(utf8_encode($row['winecol'])). '</winecol>';
    //$data .= '<acidity>' .(utf8_encode($row['acidity'])). '</acidity>';
    //$data .= '<fruit>' .(utf8_encode($row['fruit'])). '</fruit>';
    //$data .= '<tannin>' .(utf8_encode($row['tannin'])). '</tannin>';

    $data .= '<man_name>' .(utf8_encode($row['name'])). '</man_name>';
    //$data .= '<town>' .(utf8_encode($row['town'])). '</town>';
    //$data .= '<country>' .(utf8_encode($row['country'])). '</country>';
    //$data .= '<latitude>' .(utf8_encode($row['latitude'])). '</latitude>';
    //$data .= '<longitude>' .(utf8_encode($row['longitude'])). '</longitude>';

    //$data .= '<region_name>' .(utf8_encode($row['name'])). '</region_name>';
    //$data .= '<description>' .(utf8_encode($row['description'])). '</description>';
    //$data .= '<woeid>' .(utf8_encode($row['woeid'])). '</woeid>';
    //$data .= '<population>' .(utf8_encode($row['population'])). '</population>';

    //$data .= '<grape_name>' .(utf8_encode($row['name'])). '</grape_name>';
    //$data .= '<origin_country>' .(utf8_encode($row['origin_country'])). '</origin_country>';
    $data .= '</item>';
    }

    I have tried to do adjust my query multiple times and i just cant get it to work properly
    $query = "(SELECT wine.name AS winename, manufacturer.name AS manname, FROM wine, manufacturer WHERE wine.manufacturer_manufacturer_id = manufacturer.manufacturer_id)";
    This is my last attempt to simply use aliases and pull out the correct data for wine and manufacturer names
    (I have obviously adjusted 'name' to 'winename' in the while loop).

  2. #2
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,097
    Thanks
    2
    Thanked 117 Times in 114 Posts
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    "This text has been encoded with ROT26. If you can read this you must have found a backdoor. Congratulations!"


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •