Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. MySQL
  4. Query on 2 Arrays

Query on 2 Arrays

Scheduled Pinned Locked Moved MySQL
phpdatabasemysqlsysadmindata-structures
4 Posts 3 Posters 95 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    djhankypark
    wrote on last edited by
    #1

    Hi there, I have 2 MySQL databases on 2 different servers and using php am pulling an array from each of them as follows... From Server 1:

    $query_Recordset1 = "SELECT login.`id`, login.username, tbl_countries.Country
    FROM login, tbl_countries
    WHERE login.Country = tbl_countries.id ";
    $Recordset1 = mysql_query($query_Recordset1, $NU_Conn) or die(mysql_error());
    $row_Recordset1 = mysql_fetch_assoc($Recordset1);
    $totalRows_Recordset1 = mysql_num_rows($Recordset1);

    From Server 2:

    $query_Recordset2 = "SELECT newusb.ID, newusb.artist, newusb.title, tbl_ply_newusb.Week_14
    FROM newusb, tbl_ply_newusb
    WHERE tbl_ply_newusb.Song_ID = newusb.ID
    ORDER BY tbl_ply_newusb.Week_14 DESC";
    $Recordset2 = mysql_query($query_Recordset2, $Chartmenu) or die(mysql_error());
    $row_Recordset2 = mysql_fetch_assoc($Recordset2);
    $totalRows_Recordset2 = mysql_num_rows($Recordset2);

    Between the 2 arrays I am trying to find the most played artists by Country, my thought is to have some sort of join between the artist name as the artist.id does not exist in the second array. Do I create a 3rd array? if so how? Any help on how to bring in a 3rd array based on the 2 existing arrays would be appreciated. Many Thanks Ray

    M M 2 Replies Last reply
    0
    • D djhankypark

      Hi there, I have 2 MySQL databases on 2 different servers and using php am pulling an array from each of them as follows... From Server 1:

      $query_Recordset1 = "SELECT login.`id`, login.username, tbl_countries.Country
      FROM login, tbl_countries
      WHERE login.Country = tbl_countries.id ";
      $Recordset1 = mysql_query($query_Recordset1, $NU_Conn) or die(mysql_error());
      $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($Recordset1);

      From Server 2:

      $query_Recordset2 = "SELECT newusb.ID, newusb.artist, newusb.title, tbl_ply_newusb.Week_14
      FROM newusb, tbl_ply_newusb
      WHERE tbl_ply_newusb.Song_ID = newusb.ID
      ORDER BY tbl_ply_newusb.Week_14 DESC";
      $Recordset2 = mysql_query($query_Recordset2, $Chartmenu) or die(mysql_error());
      $row_Recordset2 = mysql_fetch_assoc($Recordset2);
      $totalRows_Recordset2 = mysql_num_rows($Recordset2);

      Between the 2 arrays I am trying to find the most played artists by Country, my thought is to have some sort of join between the artist name as the artist.id does not exist in the second array. Do I create a 3rd array? if so how? Any help on how to bring in a 3rd array based on the 2 existing arrays would be appreciated. Many Thanks Ray

      M Offline
      M Offline
      Mohibur Rashid
      wrote on last edited by
      #2

      how two tables are related?

      D 1 Reply Last reply
      0
      • M Mohibur Rashid

        how two tables are related?

        D Offline
        D Offline
        djhankypark
        wrote on last edited by
        #3

        Hi, The tables are related only by username. Regards Ray

        1 Reply Last reply
        0
        • D djhankypark

          Hi there, I have 2 MySQL databases on 2 different servers and using php am pulling an array from each of them as follows... From Server 1:

          $query_Recordset1 = "SELECT login.`id`, login.username, tbl_countries.Country
          FROM login, tbl_countries
          WHERE login.Country = tbl_countries.id ";
          $Recordset1 = mysql_query($query_Recordset1, $NU_Conn) or die(mysql_error());
          $row_Recordset1 = mysql_fetch_assoc($Recordset1);
          $totalRows_Recordset1 = mysql_num_rows($Recordset1);

          From Server 2:

          $query_Recordset2 = "SELECT newusb.ID, newusb.artist, newusb.title, tbl_ply_newusb.Week_14
          FROM newusb, tbl_ply_newusb
          WHERE tbl_ply_newusb.Song_ID = newusb.ID
          ORDER BY tbl_ply_newusb.Week_14 DESC";
          $Recordset2 = mysql_query($query_Recordset2, $Chartmenu) or die(mysql_error());
          $row_Recordset2 = mysql_fetch_assoc($Recordset2);
          $totalRows_Recordset2 = mysql_num_rows($Recordset2);

          Between the 2 arrays I am trying to find the most played artists by Country, my thought is to have some sort of join between the artist name as the artist.id does not exist in the second array. Do I create a 3rd array? if so how? Any help on how to bring in a 3rd array based on the 2 existing arrays would be appreciated. Many Thanks Ray

          M Offline
          M Offline
          miyasudokoro
          wrote on last edited by
          #4

          I am having trouble understanding what your table fields mean. I am assuming that Week_14 is the number of times a song was played in Week_14? In that case, you will want to use MAX(Week_14) with GROUP BY Country to get what the greatest Week_14 is for each Country (it will give you one row per country). I would need to know more about the table structure to give you more specific help than that.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups