Jump to content

Arrays

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
I'm pulling data from a SQL DB and have to combine two tables. So I have a query that runs and inside the while calls another query and retrieves data based on the first query data.

I've created an array and am storing data in it but as I'm doing it I am thinking about how this can't be the best way. I need to store 6 values, 5 from one db and 1 from the other. In the while loop I assign the data like


$myArray[i][0] = $row[...];

$myArray[i][1] = $row2[...]; // Value from second db

......


What is the best way to do this? I know there is a better way.

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
i believe you can query two tables using a UNION, however im not sure the exact syntax but i believe its something like

(SELECT a FROM table1)

UNION

(SELECT b FROM table2)

i think :confused:

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Use a join


<?php

// Make a MySQL Connection

// Construct our join query

$query = "SELECT family.Position, food.Meal ".

 "FROM family, food ".

	"WHERE family.Position = food.Position"; 


Code taken from and for more information: http://www.tizag.com.../mysqljoins.php

This is MySQL code but the query should work the same with msSQL.